eu.webtoolkit.jwt
Class WLengthValidator

java.lang.Object
  extended by eu.webtoolkit.jwt.WObject
      extended by eu.webtoolkit.jwt.WValidator
          extended by eu.webtoolkit.jwt.WLengthValidator

public class WLengthValidator
extends WValidator

A validator that checks the string length of user input.

This validator checks whether user input is within the specified range of accepted string lengths.

If you only want to limit the length on a line edit, you may also use WLineEdit#setMaxLength().

i18n

The strings used in this class can be translated by overriding the default values for the following localization keys:


Nested Class Summary
 
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WValidator
WValidator.Result, WValidator.State
 
Constructor Summary
WLengthValidator()
          Creates a length validator that accepts input of any length.
WLengthValidator(int minLength, int maxLength)
          Creates a length validator that accepts input within a length range.
WLengthValidator(int minLength, int maxLength, WObject parent)
          Creates a length validator that accepts input within a length range.
WLengthValidator(WObject parent)
          Creates a length validator that accepts input of any length.
 
Method Summary
 WString getInvalidTooLongText()
          Returns the message displayed when the input is too long.
 WString getInvalidTooShortText()
          Returns the message displayed when the input is too short.
 java.lang.String getJavaScriptValidate()
          Creates a Javascript object that validates the input.
 int getMaximumLength()
          Returns the maximum length.
 int getMinimumLength()
          Returns the minimum length.
 void setInvalidTooLongText(java.lang.CharSequence text)
          Sets the message to display when the input is too long.
 void setInvalidTooShortText(java.lang.CharSequence text)
          Sets the message to display when the input is too short.
 void setMaximumLength(int maxLength)
          Sets the maximum length.
 void setMinimumLength(int minLength)
          Sets the minimum length.
 WValidator.Result validate(java.lang.String input)
          Validates the given input.
 
Methods inherited from class eu.webtoolkit.jwt.WValidator
fixup, getInputFilter, getInvalidBlankText, isMandatory, setInvalidBlankText, setMandatory
 
Methods inherited from class eu.webtoolkit.jwt.WObject
addChild, getId, getObjectName, remove, setObjectName, tr
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WLengthValidator

public WLengthValidator(WObject parent)
Creates a length validator that accepts input of any length.


WLengthValidator

public WLengthValidator()
Creates a length validator that accepts input of any length.

Calls this((WObject)null)


WLengthValidator

public WLengthValidator(int minLength,
                        int maxLength,
                        WObject parent)
Creates a length validator that accepts input within a length range.


WLengthValidator

public WLengthValidator(int minLength,
                        int maxLength)
Creates a length validator that accepts input within a length range.

Calls this(minLength, maxLength, (WObject)null)

Method Detail

setMinimumLength

public void setMinimumLength(int minLength)
Sets the minimum length.

The default value is 0.


getMinimumLength

public int getMinimumLength()
Returns the minimum length.

See Also:
setMinimumLength(int minLength)

setMaximumLength

public void setMaximumLength(int maxLength)
Sets the maximum length.

The default value is the maximum integer value.


getMaximumLength

public int getMaximumLength()
Returns the maximum length.

See Also:
setMaximumLength(int maxLength)

validate

public WValidator.Result validate(java.lang.String input)
Validates the given input.

The input is considered valid only when it is blank for a non-mandatory field, or has a length within the valid range.

Overrides:
validate in class WValidator

setInvalidTooShortText

public void setInvalidTooShortText(java.lang.CharSequence text)
Sets the message to display when the input is too short.

Depending on whether getMaximumLength() is a real bound, the default message is "The input must have a length between {1} and {2} characters" or " "The input must be at least {1} characters".


getInvalidTooShortText

public WString getInvalidTooShortText()
Returns the message displayed when the input is too short.

See Also:
setInvalidTooShortText(CharSequence text)

setInvalidTooLongText

public void setInvalidTooLongText(java.lang.CharSequence text)
Sets the message to display when the input is too long.

Depending on whether getMinimumLength() is different from zero, the default message is "The input must have a length between {1} and {2} characters" or " "The input must be no more than {2} characters".


getInvalidTooLongText

public WString getInvalidTooLongText()
Returns the message displayed when the input is too long.

See Also:
setInvalidTooLongText(CharSequence text)

getJavaScriptValidate

public java.lang.String getJavaScriptValidate()
Description copied from class: WValidator
Creates a Javascript object that validates the input.

The JavaScript expression should evaluate to an object which contains a validate(text) function, which returns an object that contains the following two fields:

Returns an empty string if the validator does not provide a client-side validation implementationq.

Note: The signature and contract changed changed in JWt 3.1.9.

Overrides:
getJavaScriptValidate in class WValidator
See Also:
WValidator.getInputFilter()