oracle.adf.view.faces.validator
Class ByteLengthValidator

java.lang.Object
  extended byoracle.adf.view.faces.validator.ByteLengthValidator
All Implemented Interfaces:
java.util.EventListener, StateHolder, Validator

public class ByteLengthValidator
extends java.lang.Object
implements StateHolder, Validator

ByteLengthValidator is a Validator that checks the value of the corresponding component for its byte length for the set character encoding. The following algorithm is implemented:

See Also:
setMaximumMessageDetail(String)

Field Summary
static java.lang.String MAXIMUM_MESSAGE_ID
          The message identifier of the FacesMessage to be created if the maximum byte length check fails.
static java.lang.String VALIDATOR_ID
          Standard validator id for this validator.
 
Fields inherited from interface javax.faces.validator.Validator
NOT_IN_RANGE_MESSAGE_ID
 
Constructor Summary
ByteLengthValidator()
          Construct a Validator with iso-8859-1 as the encoding and zero as the maximum bytes allowed.
ByteLengthValidator(int maximum, java.lang.String encoding)
          Construct a Validator with the specified preconfigured values.
 
Method Summary
 boolean equals(java.lang.Object object)
          Compares this ByteLengthValidator with the specified Object for equality.
 java.lang.String getEncoding()
          Return the character encoding set for this Validator or iso-8859-1 if it has not been set.
protected  FacesMessage getLengthValidationFailureMessage(FacesContext context, UIComponent component, java.lang.String value)
          The FacesMessage to be returned if byte length validation fails.
 int getMaximum()
          Return the maximum bytes to be enforced by this Validator or zero if it has not been set.
 java.lang.String getMaximumMessageDetail()
          Return custom detail error message that was set for creating FacesMessage, for values that exceeds the maximum byte length.
 ValueBinding getValueBinding(java.lang.String name)
          Return the ValueBinding used to calculate the value for the specified attribute name, if any.
 int hashCode()
          Returns the hash code for this Validator.
 boolean isTransient()
           
 void restoreState(FacesContext context, java.lang.Object state)
           
 java.lang.Object saveState(FacesContext context)
           
 void setEncoding(java.lang.String encoding)
          Set the character encoding for this Validator.
 void setMaximum(int maximum)
          Set the maximum bytes to be enforced by this Validator.
 void setMaximumMessageDetail(java.lang.String maximumMessageDetail)
          Custom error message to be used, for creating detail part of the FacesMessage, when users input exceeds the maximum byte length.
 void setTransient(boolean transientValue)
           
 void setValueBinding(java.lang.String name, ValueBinding binding)
          Set the ValueBinding used to calculate the value for the specified attribute if any.
 void validate(FacesContext context, UIComponent component, java.lang.Object value)
          Validates unless it is too long, in which case throws ValidatorException.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, 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 FacesMessage to be created if the maximum byte length check fails. The message format string for this message may optionally include {0}, {1} and {2} placeholders, which will be replaced by input value, label associated with the component and the maximum bytes respectively.

See Also:
Constant Field Values

VALIDATOR_ID

public static final java.lang.String VALIDATOR_ID

Standard validator id for this validator.

See Also:
Constant Field Values
Constructor Detail

ByteLengthValidator

public ByteLengthValidator()

Construct a Validator with iso-8859-1 as the encoding and zero as the maximum bytes allowed.


ByteLengthValidator

public ByteLengthValidator(int maximum,
                           java.lang.String encoding)

Construct a Validator with the specified preconfigured values.

Parameters:
maximum - the maximum number of bytes allowed.
encoding - the Java character set encoding. This must be an encoding supported by Java.
Method Detail

setEncoding

public void setEncoding(java.lang.String encoding)

Set the character encoding for this Validator.

Parameters:
encoding - The character encoding.

getEncoding

public java.lang.String getEncoding()

Return the character encoding set for this Validator or iso-8859-1 if it has not been set.


setMaximum

public void setMaximum(int maximum)

Set the maximum bytes to be enforced by this Validator.

Parameters:
maximum - The new maximum value

getMaximum

public int getMaximum()

Return the maximum bytes to be enforced by this Validator or zero if it has not been set.


setMaximumMessageDetail

public void setMaximumMessageDetail(java.lang.String maximumMessageDetail)

Custom error message to be used, for creating detail part of the FacesMessage, when users input exceeds the maximum byte length.

Overrides detail message identified by message id MAXIMUM_MESSAGE_ID

Parameters:
maximumMessageDetail - Custom error message.

getMaximumMessageDetail

public java.lang.String getMaximumMessageDetail()

Return custom detail error message that was set for creating FacesMessage, for values that exceeds the maximum byte length.

Returns:
Custom error message.
See Also:
setMaximumMessageDetail(String)

validate

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

Validates unless it is too long, in which case throws ValidatorException.

Specified by:
validate in interface Validator
Throws:
ValidatorException - if validation fails
java.lang.NullPointerException - if context
java.nio.charset.IllegalCharsetNameException - if encoding is
java.lang.IllegalArgumentException - if value is not of type String unsupported or component is null

saveState

public java.lang.Object saveState(FacesContext context)
Specified by:
saveState in interface StateHolder

restoreState

public void restoreState(FacesContext context,
                         java.lang.Object state)
Specified by:
restoreState in interface StateHolder

isTransient

public boolean isTransient()
Specified by:
isTransient in interface StateHolder

setTransient

public void setTransient(boolean transientValue)
Specified by:
setTransient in interface StateHolder

setValueBinding

public void setValueBinding(java.lang.String name,
                            ValueBinding binding)

Set the ValueBinding used to calculate the value for the specified attribute if any.

Parameters:
name - Name of the attribute for which to set a ValueBinding
binding - The ValueBinding to set, or null to remove any currently set ValueBinding
Throws:
java.lang.NullPointerException - if name is null
java.lang.IllegalArgumentException - if name is not a valid attribute of this validator

getValueBinding

public ValueBinding getValueBinding(java.lang.String name)

Return the ValueBinding used to calculate the value for the specified attribute name, if any.

Parameters:
name - Name of the attribute or property for which to retrieve a ValueBinding
Throws:
java.lang.NullPointerException - if name is null
java.lang.IllegalArgumentException - if name is not a valid attribute of this validator

equals

public boolean equals(java.lang.Object object)

Compares this ByteLengthValidator with the specified Object for equality.

Parameters:
object - Object to which this ByteLengthValidator is to be compared.
Returns:
true if and only if the specified Object is a ByteLengthValidator and if the values encoding, maximum and transient are equal.

hashCode

public int hashCode()

Returns the hash code for this Validator.

Returns:
a hash code value for this object.

getLengthValidationFailureMessage

protected FacesMessage getLengthValidationFailureMessage(FacesContext context,
                                                         UIComponent component,
                                                         java.lang.String value)
The FacesMessage to be returned if byte length validation fails.

Parameters:
context - Faces context
value - The value entered / set by the user on the component
Returns:
error message when the length exceeds the maximum byte length set.


Copyright © 2003-2007 Oracle Corporation. All Rights Reserved.