Top Description Fields Constructors Methods
javax.faces.validator

public Class LongRangeValidator

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

LongRangeValidator is a Validator that checks the value of the corresponding component against specified minimum and maximum values. 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 javax.faces.Number. This allows the values to be localized according to the current Locale.

Field Summary

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

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

private Long
public static final String
MINIMUM_MESSAGE_ID

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

public static final String
NOT_IN_RANGE_MESSAGE_ID

Hides javax.faces.validator.Validator.NOT_IN_RANGE_MESSAGE_ID.

The message identifier of the javax.faces.application.FacesMessage to be created if the maximum or minimum value check fails, and both the maximum and minimum values for this validator have been set.

private boolean
public static final String
TYPE_MESSAGE_ID

The message identifier of the javax.faces.application.FacesMessage to be created if the current value of this component is not of the correct type.

public static final String
VALIDATOR_ID

The standard converter id for this converter.

Constructor Summary

AccessConstructor and Description
public
LongRangeValidator()

Construct a Validator with no preconfigured limits.

public
LongRangeValidator(long
Maximum value to allow
maximum
)

Construct a Validator with the specified preconfigured limit.

public
LongRangeValidator(long
Maximum value to allow
maximum
,
long
Minimum value to allow
minimum
)

Construct a Validator with the specified preconfigured limits.

Method Summary

Modifier and TypeMethod and Description
public void
clearInitialState()

Implements javax.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 long

Returns:

the maximum
getMaximum
()

Return the maximum value to be enforced by this Validator.

public long

Returns:

the minimum
getMinimum
()

Return the minimum value to be enforced by this Validator.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public boolean
initialStateMarked()

Implements javax.faces.component.PartialStateHolder.initialStateMarked.

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

private boolean
private boolean
public boolean
isTransient()

Implements javax.faces.component.StateHolder.isTransient.

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

private static long
longValue(Object
The attribute value to be converted
attributeValue
)

Return the specified attribute value, converted to a long.

public void
markInitialState()

Implements javax.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 javax.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 javax.faces.component.StateHolder.saveState.

Gets the state of the instance as a Serializable Object.

public void
setMaximum(long
The new maximum value
maximum
)

Set the maximum value to be enforced by this Validator.

public void
setMinimum(long
The new minimum value
minimum
)

Set the minimum value 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 javax.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(UIComponent component, Long toConvert, FacesContext context)

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 javax.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 Long maximum
MAXIMUM_MESSAGE_IDback to summary
public static final String MAXIMUM_MESSAGE_ID

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

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

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

  • {0} replaced by the configured minimum value.
  • {1} replaced by a String whose value is the label of the input component that produced this message.
NOT_IN_RANGE_MESSAGE_IDback to summary
public static final String NOT_IN_RANGE_MESSAGE_ID

Hides javax.faces.validator.Validator.NOT_IN_RANGE_MESSAGE_ID.

The message identifier of the javax.faces.application.FacesMessage to be created if the maximum or minimum value check fails, and both the maximum and minimum values for this validator have been set. The message format string for this message may optionally include the following placeholders:

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

The message identifier of the javax.faces.application.FacesMessage to be created if the current value of this component is not of the correct type. The message format string for this message may optionally include a {0} placeholder that will be replaced by a String whose value is the label of the input component that produced this message.

VALIDATOR_IDback to summary
public static final String VALIDATOR_ID

The standard converter id for this converter.

Constructor Detail

LongRangeValidatorback to summary
public LongRangeValidator()

Construct a Validator with no preconfigured limits.

LongRangeValidatorback to summary
public LongRangeValidator(long maximum)

Construct a Validator with the specified preconfigured limit.

Parameters
maximum:long

Maximum value to allow

LongRangeValidatorback to summary
public LongRangeValidator(long maximum, long minimum)

Construct a Validator with the specified preconfigured limits.

Parameters
maximum:long

Maximum value to allow

minimum:long

Minimum value to allow

Method Detail

clearInitialStateback to summary
public void clearInitialState()

Implements javax.faces.component.PartialStateHolder.clearInitialState.

Doc from javax.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 long getMaximum()

Return the maximum value to be enforced by this Validator.

Returns:long

the maximum

getMinimumback to summary
public long getMinimum()

Return the minimum value to be enforced by this Validator.

Returns:long

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 the 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 javax.faces.component.PartialStateHolder.initialStateMarked.

Doc from javax.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
isMaximumSetback to summary
private boolean isMaximumSet()
isMinimumSetback to summary
private boolean isMinimumSet()
isTransientback to summary
public boolean isTransient()

Implements javax.faces.component.StateHolder.isTransient.

Doc from javax.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
longValueback to summary
private static long longValue(Object attributeValue) throws NumberFormatException

Return the specified attribute value, converted to a long.

Parameters
attributeValue:Object

The attribute value to be converted

Exceptions
NumberFormatException:
if conversion is not possible
markInitialStateback to summary
public void markInitialState()

Implements javax.faces.component.PartialStateHolder.markInitialState.

Doc from javax.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 javax.faces.component.StateHolder.restoreState.

Doc from javax.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 javax.faces.component.StateHolder.saveState.

Doc from javax.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 javax.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(long maximum)

Set the maximum value to be enforced by this Validator.

Parameters
maximum:long

The new maximum value

setMinimumback to summary
public void setMinimum(long minimum)

Set the minimum value to be enforced by this Validator.

Parameters
minimum:long

The new minimum value

setTransientback to summary
public void setTransient(boolean transientValue)

Implements javax.faces.component.StateHolder.setTransient.

Doc from javax.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(UIComponent component, Long toConvert, FacesContext context)
validateback to summary
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException

Implements javax.faces.validator.Validator.validate.

Doc from javax.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 javax.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 JSF 1.2 to work with JSF 2 and later. The javax.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