com.vaadin.data.validator
Class StringLengthValidator

java.lang.Object
  extended by com.vaadin.data.validator.AbstractValidator<String>
      extended by com.vaadin.data.validator.AbstractStringValidator
          extended by com.vaadin.data.validator.StringLengthValidator
All Implemented Interfaces:
Validator, Serializable

public class StringLengthValidator
extends AbstractStringValidator

This StringLengthValidator is used to validate the length of strings.

Since:
3.0
Version:
7.0.0.alpha3
Author:
Vaadin Ltd.
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.vaadin.data.Validator
Validator.EmptyValueException, Validator.InvalidValueException
 
Constructor Summary
StringLengthValidator(String errorMessage)
          Creates a new StringLengthValidator with a given error message.
StringLengthValidator(String errorMessage, Integer minLength, Integer maxLength, boolean allowNull)
          Creates a new StringLengthValidator with a given error message and minimum and maximum length limits.
 
Method Summary
 Integer getMaxLength()
          Gets the maximum permissible length of the string.
 Integer getMinLength()
          Gets the minimum permissible length of the string.
 boolean isNullAllowed()
          Deprecated. 
protected  boolean isValidValue(String value)
          Checks if the given value is valid.
 void setMaxLength(Integer maxLength)
          Sets the maximum permissible length of the string.
 void setMinLength(Integer minLength)
          Sets the minimum permissible length.
 void setNullAllowed(boolean allowNull)
          Deprecated. 
 
Methods inherited from class com.vaadin.data.validator.AbstractStringValidator
getType
 
Methods inherited from class com.vaadin.data.validator.AbstractValidator
getErrorMessage, isValid, isValidType, setErrorMessage, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringLengthValidator

public StringLengthValidator(String errorMessage)
Creates a new StringLengthValidator with a given error message.

Parameters:
errorMessage - the message to display in case the value does not validate.

StringLengthValidator

public StringLengthValidator(String errorMessage,
                             Integer minLength,
                             Integer maxLength,
                             boolean allowNull)
Creates a new StringLengthValidator with a given error message and minimum and maximum length limits.

Parameters:
errorMessage - the message to display in case the value does not validate.
minLength - the minimum permissible length of the string or null for no limit. A negative value for no limit is also supported for backwards compatibility.
maxLength - the maximum permissible length of the string or null for no limit. A negative value for no limit is also supported for backwards compatibility.
allowNull - Are null strings permissible? This can be handled better by setting a field as required or not.
Method Detail

isValidValue

protected boolean isValidValue(String value)
Checks if the given value is valid.

Specified by:
isValidValue in class AbstractValidator<String>
Parameters:
value - the value to validate.
Returns:
true for valid value, otherwise false.

isNullAllowed

@Deprecated
public final boolean isNullAllowed()
Deprecated. 

Returns true if null strings are allowed.

Returns:
true if allows null string, otherwise false.

getMaxLength

public Integer getMaxLength()
Gets the maximum permissible length of the string.

Returns:
the maximum length of the string or null if there is no limit

getMinLength

public Integer getMinLength()
Gets the minimum permissible length of the string.

Returns:
the minimum length of the string or null if there is no limit

setNullAllowed

@Deprecated
public void setNullAllowed(boolean allowNull)
Deprecated. 

Sets whether null-strings are to be allowed. This can be better handled by setting a field as required or not.


setMaxLength

public void setMaxLength(Integer maxLength)
Sets the maximum permissible length of the string.

Parameters:
maxLength - the maximum length to accept or null for no limit

setMinLength

public void setMinLength(Integer minLength)
Sets the minimum permissible length.

Parameters:
minLength - the minimum length to accept or null for no limit


Copyright © 2000-2011 Vaadin Ltd. All Rights Reserved.