com.sun.rave.web.ui.validator
Class StringLengthValidator

java.lang.Object
  extended by com.sun.rave.web.ui.validator.StringLengthValidator
All Implemented Interfaces:
java.util.EventListener, javax.faces.component.StateHolder, javax.faces.validator.Validator

public class StringLengthValidator
extends java.lang.Object
implements javax.faces.validator.Validator, javax.faces.component.StateHolder

Use this validator to check the number of characters in a string when you need to set the validation messages.


Field Summary
static java.lang.String VALIDATOR_ID
          The converter id for this converter.
 
Fields inherited from interface javax.faces.validator.Validator
NOT_IN_RANGE_MESSAGE_ID
 
Constructor Summary
StringLengthValidator()
          Creates a new instance of StringLengthValidator
StringLengthValidator(int max)
          Creates a new instance of StringLengthValidator.
StringLengthValidator(int max, int min)
          Creates a new instance of StringLengthValidator.
 
Method Summary
 java.lang.String getTooLongMessage()
          Get the message to be used if the string is longer than the maxmimum number of characters.
 java.lang.String getTooShortMessage()
          Get the message to be used if the string is shorter than the minimum number of characters.
 boolean isTransient()
          Returns false, this component needs to save state.
 void restoreState(javax.faces.context.FacesContext context, java.lang.Object state)
          Restore the state of the component.
 java.lang.Object saveState(javax.faces.context.FacesContext context)
          Saves the state of the component into an object
 void setTooLongMessage(java.lang.String tooLongMessage)
          Set the message to be used if the string is longer than the maximum number of characters.
 void setTooShortMessage(java.lang.String tooShortMessage)
          Set the message to be used if the string is shorter than the minimum number of characters.
 void setTransient(boolean transientValue)
          Does nothing
 void validate(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.Object value)
           Validate the value with regard to a UIComponent and a FacesContext.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VALIDATOR_ID

public static final java.lang.String VALIDATOR_ID

The converter id for this converter.

See Also:
Constant Field Values
Constructor Detail

StringLengthValidator

public StringLengthValidator()
Creates a new instance of StringLengthValidator


StringLengthValidator

public StringLengthValidator(int max)
Creates a new instance of StringLengthValidator.

Parameters:
max - The maximum number of characters allowed in the string

StringLengthValidator

public StringLengthValidator(int max,
                             int min)
Creates a new instance of StringLengthValidator.

Parameters:
max - The maximum number of characters allowed in the string
min - The minimum number of characters allowed in the string
Method Detail

validate

public void validate(javax.faces.context.FacesContext context,
                     javax.faces.component.UIComponent component,
                     java.lang.Object value)
              throws javax.faces.validator.ValidatorException

Validate the value with regard to a UIComponent and a FacesContext.

Specified by:
validate in interface javax.faces.validator.Validator
Parameters:
context - The FacesContext
component - The component to be validated
value - The submitted value of the component
Throws:
javax.faces.validator.ValidatorException - if the value is not valid

saveState

public java.lang.Object saveState(javax.faces.context.FacesContext context)
Saves the state of the component into an object

Specified by:
saveState in interface javax.faces.component.StateHolder
Parameters:
context - the FacesContext
Returns:
the Object representing the state of the component

restoreState

public void restoreState(javax.faces.context.FacesContext context,
                         java.lang.Object state)
Restore the state of the component.

Specified by:
restoreState in interface javax.faces.component.StateHolder
Parameters:
context - The FacesContext
state - the Object representing the state of the component

isTransient

public boolean isTransient()
Returns false, this component needs to save state.

Specified by:
isTransient in interface javax.faces.component.StateHolder
Returns:
false

setTransient

public void setTransient(boolean transientValue)
Does nothing

Specified by:
setTransient in interface javax.faces.component.StateHolder

getTooLongMessage

public java.lang.String getTooLongMessage()
Get the message to be used if the string is longer than the maxmimum number of characters.

Returns:
the message to be used if the string is longer than the maxmimum number of characters

setTooLongMessage

public void setTooLongMessage(java.lang.String tooLongMessage)
Set the message to be used if the string is longer than the maximum number of characters.

Parameters:
tooLongMessage - the message to be used if the string is longer than the maxmimum number of characters

getTooShortMessage

public java.lang.String getTooShortMessage()
Get the message to be used if the string is shorter than the minimum number of characters.

Returns:
the message to be used if the string is shorter than the minimum number of characters

setTooShortMessage

public void setTooShortMessage(java.lang.String tooShortMessage)
Set the message to be used if the string is shorter than the minimum number of characters.

Parameters:
tooShortMessage - the message to be used if the string is shorter than the minimum number of characters