javax.faces.validator
Class LengthValidator

java.lang.Object
  extended byjavax.faces.validator.ValidatorBase
      extended byjavax.faces.validator.LengthValidator
All Implemented Interfaces:
java.io.Serializable, Validator

public class LengthValidator
extends javax.faces.validator.ValidatorBase

LengthValidator is a Validator that checks the number of characters in the String representation of the value of the associated component. The following algorithm is implemented:

See Also:
Serialized Form

Field Summary
static java.lang.String MAXIMUM_MESSAGE_ID
          The message identifier of the Message to be created if the maximum length check fails.
static java.lang.String MINIMUM_MESSAGE_ID
          The message identifier of the Message to be created if the minimum length check fails.
 
Constructor Summary
LengthValidator()
          Construct a Validator with no preconfigured limits.
LengthValidator(int maximum)
          Construct a Validator with the specified preconfigured limit.
LengthValidator(int maximum, int minimum)
          Construct a Validator with the specified preconfigured limits.
 
Method Summary
protected  double doubleValue(java.lang.Object attributeValue)
          Return the specified attribute value, converted to a double.
 int getMaximum()
          Return the maximum length to be enforced by this Validator, or 0 if the maximum has not been set.
protected  Message getMessage(FacesContext context, java.lang.String messageId)
          Return a Message for the specified parameters.
protected  Message getMessage(FacesContext context, java.lang.String messageId, java.lang.Object[] params)
          Return a Message for the specified parameters.
protected  MessageResources getMessageResources()
          Return the MessageResources instance for the message resources defined by the JavaServer Faces Specification.
 int getMinimum()
          Return the minimum length to be enforced by this Validator, or 0 if the minimum has not been set.
 boolean isMaximumSet()
          Return a flag indicating whether a maximum length has been set.
 boolean isMinimumSet()
          Return a flag indicating whether a minimum limit has been set.
protected  long longValue(java.lang.Object attributeValue)
          Return the specified attribute value, converted to a long.
 void setMaximum(int maximum)
          Set the maximum length to be enforced by this Validator.
 void setMinimum(int minimum)
          Set the minimum length to be enforced by this Validator.
protected  java.lang.String stringValue(java.lang.Object attributeValue)
          Return the specified attribute value, converted to a String.
 void validate(FacesContext context, UIComponent component)
          Perform the correctness checks implemented by this Validator against the specified UIComponent.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAXIMUM_MESSAGE_ID

public static final java.lang.String MAXIMUM_MESSAGE_ID

The message identifier of the Message to be created if the maximum length check fails. The message format string for this message may optionally include a {0} placeholder, which will be replaced by the configured maximum length.

See Also:
Constant Field Values

MINIMUM_MESSAGE_ID

public static final java.lang.String MINIMUM_MESSAGE_ID

The message identifier of the Message to be created if the minimum length check fails. The message format string for this message may optionally include a {0} placeholder, which will be replaced by the configured minimum length.

See Also:
Constant Field Values
Constructor Detail

LengthValidator

public LengthValidator()

Construct a Validator with no preconfigured limits.


LengthValidator

public LengthValidator(int maximum)

Construct a Validator with the specified preconfigured limit.

Parameters:
maximum - Maximum value to allow

LengthValidator

public LengthValidator(int maximum,
                       int minimum)

Construct a Validator with the specified preconfigured limits.

Parameters:
maximum - Maximum value to allow
minimum - Minimum value to allow
Throws:
java.lang.IllegalArgumentException - if a specified maximum value is less than a specified minimum value
Method Detail

getMaximum

public int getMaximum()

Return the maximum length to be enforced by this Validator, or 0 if the maximum has not been set.


setMaximum

public void setMaximum(int maximum)

Set the maximum length to be enforced by this Validator.

Parameters:
maximum - The new maximum value
Throws:
java.lang.IllegalArgumentException - if a specified maximum value is less than a specified minimum value

isMaximumSet

public boolean isMaximumSet()

Return a flag indicating whether a maximum length has been set.


getMinimum

public int getMinimum()

Return the minimum length to be enforced by this Validator, or 0 if the minimum has not been set.


setMinimum

public void setMinimum(int minimum)

Set the minimum length to be enforced by this Validator.

Parameters:
minimum - The new minimum value
Throws:
java.lang.IllegalArgumentException - if a specified maximum value is less than a specified minimum value

isMinimumSet

public boolean isMinimumSet()

Return a flag indicating whether a minimum limit has been set.


validate

public void validate(FacesContext context,
                     UIComponent component)
Description copied from interface: Validator

Perform the correctness checks implemented by this Validator against the specified UIComponent. If any violations are found:


getMessage

protected Message getMessage(FacesContext context,
                             java.lang.String messageId)

Return a Message for the specified parameters.

Parameters:
context - The FacesContext associated with the request being processed
messageId - Message identifier of the requested message

getMessage

protected Message getMessage(FacesContext context,
                             java.lang.String messageId,
                             java.lang.Object[] params)

Return a Message for the specified parameters.

Parameters:
context - The FacesContext associated with the request being processed
messageId - Message identifier of the requested message
params - Substitution parameters for this message

getMessageResources

protected MessageResources getMessageResources()

Return the MessageResources instance for the message resources defined by the JavaServer Faces Specification.


doubleValue

protected double doubleValue(java.lang.Object attributeValue)
                      throws java.lang.NumberFormatException

Return the specified attribute value, converted to a double.

Parameters:
attributeValue - The attribute value to be converted
Throws:
java.lang.NumberFormatException - if conversion is not possible

longValue

protected long longValue(java.lang.Object attributeValue)
                  throws java.lang.NumberFormatException

Return the specified attribute value, converted to a long.

Parameters:
attributeValue - The attribute value to be converted
Throws:
java.lang.NumberFormatException - if conversion is not possible

stringValue

protected java.lang.String stringValue(java.lang.Object attributeValue)

Return the specified attribute value, converted to a String.

Parameters:
attributeValue - The attribute value to be converted