Top Description Fields Constructors Methods
jakarta.faces.validator

public Class DoubleRangeValidator

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

DoubleRangeValidator 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 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 Double
public static final String
MAXIMUM_MESSAGE_ID

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

private Double
public static final String
MINIMUM_MESSAGE_ID

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

public static final String
NOT_IN_RANGE_MESSAGE_ID

The message identifier of the jakarta.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 jakarta.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
DoubleRangeValidator()

Construct a Validator with no preconfigured limits.

public
DoubleRangeValidator(double
Maximum value to allow
maximum
)

Construct a Validator with the specified preconfigured limit.

public
DoubleRangeValidator(double
Maximum value to allow
maximum
,
double
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.

private static double
doubleValue(Object
The attribute value to be converted
attributeValue
)

Return the specified attribute value, converted to a double.

public boolean

Returns:

true if equal, false otherwise.
equals
(Object
the object to compare against.
otherObj
)

Overrides java.lang.Object.equals.

Overrides the default equals method to take the minimum and maximum into account when comparing DoubleRangeValidator instances.

public double

Returns:

the maximum
getMaximum
()

Return the maximum value to be enforced by this Validator or Double.MAX_VALUE if it has not been set.

public double

Returns:

the minimum value
getMinimum
()

Return the minimum value to be enforced by this Validator, or Double.MIN_VALUE if it has not been set.

public int

Returns:

the hash code.
hashCode
()

Overrides java.lang.Object.hashCode.

Overrides the default hash code method to take the minimum and maximum into account when generating the hash code.

public boolean
initialStateMarked()

Implements jakarta.faces.component.PartialStateHolder.initialStateMarked.

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

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(double
The new maximum value
maximum
)

Set the maximum value to be enforced by this Validator.

public void
setMinimum(double
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 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(UIComponent component, Double 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 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 Double 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 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 Double 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 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

The message identifier of the jakarta.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 jakarta.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

DoubleRangeValidatorback to summary
public DoubleRangeValidator()

Construct a Validator with no preconfigured limits.

DoubleRangeValidatorback to summary
public DoubleRangeValidator(double maximum)

Construct a Validator with the specified preconfigured limit.

Parameters
maximum:double

Maximum value to allow

DoubleRangeValidatorback to summary
public DoubleRangeValidator(double maximum, double minimum)

Construct a Validator with the specified preconfigured limits.

Parameters
maximum:double

Maximum value to allow

minimum:double

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
doubleValueback to summary
private static double doubleValue(Object attributeValue) throws NumberFormatException

Return the specified attribute value, converted to a double.

Parameters
attributeValue:Object

The attribute value to be converted

Exceptions
NumberFormatException:
if conversion is not possible
equalsback to summary
public boolean equals(Object otherObj)

Overrides java.lang.Object.equals.

Overrides the default equals method to take the minimum and maximum into account when comparing DoubleRangeValidator instances.

Parameters
otherObj:Object

the object to compare against.

Returns:boolean

true if equal, false otherwise.

Annotations
@Override
getMaximumback to summary
public double getMaximum()

Return the maximum value to be enforced by this Validator or Double.MAX_VALUE if it has not been set.

Returns:double

the maximum

getMinimumback to summary
public double getMinimum()

Return the minimum value to be enforced by this Validator, or Double.MIN_VALUE if it has not been set.

Returns:double

the minimum value

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Overrides the default hash code method to take the minimum and maximum into account when generating the hash code.

Returns:int

the hash code.

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
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(double maximum)

Set the maximum value to be enforced by this Validator.

Parameters
maximum:double

The new maximum value

setMinimumback to summary
public void setMinimum(double minimum)

Set the minimum value to be enforced by this Validator.

Parameters
minimum:double

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(UIComponent component, Double toConvert, FacesContext context)
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