Top Description Fields Constructors Methods
jakarta.faces.validator

public Class LengthValidator

extends Object
implements Validator, PartialStateHolder
Class Inheritance
All Implemented Interfaces
jakarta.faces.component.PartialStateHolder, jakarta.faces.component.StateHolder, jakarta.faces.validator.Validator, java.util.EventListener
Imports
jakarta.faces.component.PartialStateHolder, .UIComponent, jakarta.faces.context.FacesContext, jakarta.faces.convert.Converter

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:

For all of the above cases that cause a ValidatorException to be thrown, if there are parameters to the message that match up with validator parameters, the values of these parameters must be converted using the Converter registered in the application under the converter id jakarta.faces.Number. This allows the values to be localized according to the current Locale.

Field Summary

Modifier and TypeField and Description
private boolean
private Integer
public static final String
MAXIMUM_MESSAGE_ID

The message identifier of the jakarta.faces.application.FacesMessage to be created if the maximum length check fails.

private Integer
public static final String
MINIMUM_MESSAGE_ID

The message identifier of the jakarta.faces.application.FacesMessage to be created if the minimum length check fails.

private boolean
public static final String
VALIDATOR_ID

The standard validator id for this validator.

Constructor Summary

AccessConstructor and Description
public
LengthValidator()

Construct a Validator with no preconfigured limits.

public
LengthValidator(int
Maximum value to allow
maximum
)

Construct a Validator with the specified preconfigured limit.

public
LengthValidator(int
Maximum value to allow
maximum
,
int
Minimum value to allow
minimum
)

Construct a Validator with the specified preconfigured limits.

Method Summary

Modifier and TypeMethod and Description
public void
clearInitialState()

Implements jakarta.faces.component.PartialStateHolder.clearInitialState.

Reset the PartialStateHolder to a non-delta tracking state.

public boolean
equals(Object
the reference object with which to compare.
otherObj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public int

Returns:

the maximum
getMaximum
()

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

public int

Returns:

the minimum
getMinimum
()

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

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean
initialStateMarked()

Implements jakarta.faces.component.PartialStateHolder.initialStateMarked.

Return true if delta state changes are being tracked, otherwise false

private static String
integerToString(UIComponent component, Integer toConvert, FacesContext context)

private boolean
private boolean
public boolean
isTransient()

Implements jakarta.faces.component.StateHolder.isTransient.

If true, the Object implementing this interface must not participate in state saving or restoring.

public void
markInitialState()

Implements jakarta.faces.component.PartialStateHolder.markInitialState.

The runtime must ensure that the markInitialState method is called on each instance of this interface in the view at the appropriate time to indicate the component is in its initial state.

public void
restoreState(FacesContext
the Faces context.
context
,
Object
the state.
state
)

Implements jakarta.faces.component.StateHolder.restoreState.

Perform any processing required to restore the state from the entries in the state Object.

public Object
saveState(FacesContext
the Faces context.
context
)

Implements jakarta.faces.component.StateHolder.saveState.

Gets the state of the instance as a Serializable Object.

public void
setMaximum(int
The new maximum value
maximum
)

Set the maximum length to be enforced by this Validator.

public void
setMinimum(int
The new minimum value
minimum
)

Set the minimum length to be enforced by this Validator.

public void
setTransient(boolean
boolean pass true if this Object will not participate in state saving or restoring, otherwise pass false.
transientValue
)

Implements jakarta.faces.component.StateHolder.setTransient.

Denotes whether or not the Object implementing this interface must or must not participate in state saving or restoring.

private static String
stringValue(Object
The attribute value to be converted
attributeValue
)

Return the specified attribute value, converted to a String.

public void
validate(FacesContext
FacesContext for the request we are processing
context
,
UIComponent
UIComponent we are checking for correctness
component
,
Object
the value to validate
value
)

Implements jakarta.faces.validator.Validator.validate.

Perform the correctness checks implemented by this Validator against the specified UIComponent.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

initialStateback to summary
private boolean initialState
maximumback to summary
private Integer maximum
MAXIMUM_MESSAGE_IDback to summary
public static final String MAXIMUM_MESSAGE_ID

The message identifier of the jakarta.faces.application.FacesMessage to be created if the maximum length check fails. The message format string for this message may optionally include the following placeholders:

  • {0} replaced by the configured maximum length.
  • {1} replaced by a String whose value is the label of the input component that produced this message.
minimumback to summary
private Integer minimum
MINIMUM_MESSAGE_IDback to summary
public static final String MINIMUM_MESSAGE_ID

The message identifier of the jakarta.faces.application.FacesMessage to be created if the minimum length check fails. The message format string for this message may optionally include the following placeholders:

  • {0} replaced by the configured minimum length.
  • {1} replaced by a String whose value is the label of the input component that produced this message.
transientValueback to summary
private boolean transientValue
VALIDATOR_IDback to summary
public static final String VALIDATOR_ID

The standard validator id for this validator.

Constructor Detail

LengthValidatorback to summary
public LengthValidator()

Construct a Validator with no preconfigured limits.

LengthValidatorback to summary
public LengthValidator(int maximum)

Construct a Validator with the specified preconfigured limit.

Parameters
maximum:int

Maximum value to allow

LengthValidatorback to summary
public LengthValidator(int maximum, int minimum)

Construct a Validator with the specified preconfigured limits.

Parameters
maximum:int

Maximum value to allow

minimum:int

Minimum value to allow

Method Detail

clearInitialStateback to summary
public void clearInitialState()

Implements jakarta.faces.component.PartialStateHolder.clearInitialState.

Doc from jakarta.faces.component.PartialStateHolder.clearInitialState.

Reset the PartialStateHolder to a non-delta tracking state.

Annotations
@Override
equalsback to summary
public boolean equals(Object otherObj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
otherObj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getMaximumback to summary
public int getMaximum()

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

Returns:int

the maximum

getMinimumback to summary
public int getMinimum()

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

Returns:int

the minimum

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
initialStateMarkedback to summary
public boolean initialStateMarked()

Implements jakarta.faces.component.PartialStateHolder.initialStateMarked.

Doc from jakarta.faces.component.PartialStateHolder.initialStateMarked.

Return true if delta state changes are being tracked, otherwise false

Returns:boolean

true if the initial state is marked, false otherwise.

Annotations
@Override
integerToStringback to summary
private static String integerToString(UIComponent component, Integer toConvert, FacesContext context)
isMaximumSetback to summary
private boolean isMaximumSet()
isMinimumSetback to summary
private boolean isMinimumSet()
isTransientback to summary
public boolean isTransient()

Implements jakarta.faces.component.StateHolder.isTransient.

Doc from jakarta.faces.component.StateHolder.isTransient.

If true, the Object implementing this interface must not participate in state saving or restoring.

Returns:boolean

true if transient, false otherwise.

Annotations
@Override
markInitialStateback to summary
public void markInitialState()

Implements jakarta.faces.component.PartialStateHolder.markInitialState.

Doc from jakarta.faces.component.PartialStateHolder.markInitialState.

The runtime must ensure that the markInitialState method is called on each instance of this interface in the view at the appropriate time to indicate the component is in its initial state. The implementor of the interface must ensure that initialStateMarked returns true from the time markInitialState() is called until clearInitialState is called, after which time initialStateMarked() must return false. Also, during the time that the instance returns true from initialStateMarked(), the implementation must return only the state that has changed in its implementation of StateHolder#saveState.

Annotations
@Override
restoreStateback to summary
public void restoreState(FacesContext context, Object state)

Implements jakarta.faces.component.StateHolder.restoreState.

Doc from jakarta.faces.component.StateHolder.restoreState.

Perform any processing required to restore the state from the entries in the state Object.

If the class that implements this interface has references to instances that also implement StateHolder (such as a UIComponent with event handlers, validators, etc.) this method must call the restoreState method on all those instances as well.

If the state argument is null, take no action and return.

Parameters
context:FacesContext

the Faces context.

state:Object

the state.

Annotations
@Override
saveStateback to summary
public Object saveState(FacesContext context)

Implements jakarta.faces.component.StateHolder.saveState.

Doc from jakarta.faces.component.StateHolder.saveState.

Gets the state of the instance as a Serializable Object.

If the class that implements this interface has references to instances that implement StateHolder (such as a UIComponent with event handlers, validators, etc.) this method must call the saveState method on all those instances as well. This method must not save the state of children and facets. That is done via the jakarta.faces.application.StateManager

This method must not alter the state of the implementing object. In other words, after executing this code:


Object state = component.saveState(facesContext);

component should be the same as before executing it.

The return from this method must be Serializable

Parameters
context:FacesContext

the Faces context.

Returns:Object

the saved state.

Annotations
@Override
setMaximumback to summary
public void setMaximum(int maximum)

Set the maximum length to be enforced by this Validator.

Parameters
maximum:int

The new maximum value

setMinimumback to summary
public void setMinimum(int minimum)

Set the minimum length to be enforced by this Validator.

Parameters
minimum:int

The new minimum value

setTransientback to summary
public void setTransient(boolean transientValue)

Implements jakarta.faces.component.StateHolder.setTransient.

Doc from jakarta.faces.component.StateHolder.setTransient.

Denotes whether or not the Object implementing this interface must or must not participate in state saving or restoring.

Parameters
transientValue:boolean

boolean pass true if this Object will not participate in state saving or restoring, otherwise pass false.

Annotations
@Override
stringValueback to summary
private static String stringValue(Object attributeValue)

Return the specified attribute value, converted to a String.

Parameters
attributeValue:Object

The attribute value to be converted

validateback to summary
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException

Implements jakarta.faces.validator.Validator.validate.

Doc from jakarta.faces.validator.Validator.validate.

Perform the correctness checks implemented by this Validator against the specified UIComponent. If any violations are found, a ValidatorException will be thrown containing the jakarta.faces.application.FacesMessage describing the failure.

For a validator to be fully compliant with Version 2 and later of the specification, it must not fail validation on null or empty values unless it is specifically intended to address null or empty values. An application-wide <context-param> is provided to allow validators designed for Jakarta Faces 1.2 to work with Jakarta Faces 2 and later. The jakarta.faces.VALIDATE_EMPTY_FIELDS <context-param> must be set to false to enable this backwards compatibility behavior.

Parameters
context:FacesContext

FacesContext for the request we are processing

component:UIComponent

UIComponent we are checking for correctness

value:Object

the value to validate

Annotations
@Override
Exceptions
ValidatorException:
if validation fails
NullPointerException:
if context or component is null