com.itmill.toolkit.data.validator
Class StringLengthValidator

java.lang.Object
  extended by com.itmill.toolkit.data.validator.StringLengthValidator
All Implemented Interfaces:
Validator

public class StringLengthValidator
extends Object
implements Validator

This StringLengthValidator is used to validate the length of strings.

Since:
3.0
Version:
5.3.0
Author:
IT Mill Ltd.

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.itmill.toolkit.data.Validator
Validator.EmptyValueException, Validator.InvalidValueException
 
Constructor Summary
StringLengthValidator(String errorMessage)
          Creates a new StringLengthValidator with a given error message.
StringLengthValidator(String errorMessage, int minLength, int maxLength, boolean allowNull)
          Creates a new StringLengthValidator with a given error message, permissable lengths and null-string allowance.
 
Method Summary
 String getErrorMessage()
          Gets the message to be displayed in case the value does not validate.
 int getMaxLength()
          Gets the maximum permissable length of the string.
 int getMinLength()
          Gets the minimum permissable length of the string.
 boolean isNullAllowed()
          Returns true if null strings are allowed.
 boolean isValid(Object value)
          Checks if the given value is valid.
 void setErrorMessage(String errorMessage)
          Sets the message to be displayer in case the value does not validate.
 void setMaxLength(int maxLength)
          Sets the maximum permissable length of the string.
 void setMinLength(int minLength)
          Sets the minimum permissable length.
 void setNullAllowed(boolean allowNull)
          Sets whether null-strings are to be allowed.
 void validate(Object value)
          Validates the value.
 
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,
                             int minLength,
                             int maxLength,
                             boolean allowNull)
Creates a new StringLengthValidator with a given error message, permissable lengths and null-string allowance.

Parameters:
errorMessage - the message to display in case the value does not validate.
minLength - the minimum permissable length of the string.
maxLength - the maximum permissable length of the string.
allowNull - Are null strings permissable?
Method Detail

validate

public void validate(Object value)
              throws Validator.InvalidValueException
Validates the value.

Specified by:
validate in interface Validator
Parameters:
value - the value to validate.
Throws:
Validator.InvalidValueException - if the value was invalid.

isValid

public boolean isValid(Object value)
Checks if the given value is valid.

Specified by:
isValid in interface Validator
Parameters:
value - the value to validate.
Returns:
true for valid value, otherwise false.

isNullAllowed

public final boolean isNullAllowed()
Returns true if null strings are allowed.

Returns:
true if allows null string, otherwise false.

getMaxLength

public final int getMaxLength()
Gets the maximum permissable length of the string.

Returns:
the maximum length of the string.

getMinLength

public final int getMinLength()
Gets the minimum permissable length of the string.

Returns:
the minimum length of the string.

setNullAllowed

public void setNullAllowed(boolean allowNull)
Sets whether null-strings are to be allowed.


setMaxLength

public void setMaxLength(int maxLength)
Sets the maximum permissable length of the string.

Parameters:
maxLength - the length to set.

setMinLength

public void setMinLength(int minLength)
Sets the minimum permissable length.

Parameters:
minLength - the length to set.

getErrorMessage

public String getErrorMessage()
Gets the message to be displayed in case the value does not validate.

Returns:
the Error Message.

setErrorMessage

public void setErrorMessage(String errorMessage)
Sets the message to be displayer in case the value does not validate.

Parameters:
errorMessage - the Error Message to set.


Copyright © 2000-2009 IT Mill Ltd. All Rights Reserved.