Interface Validator
- All Superinterfaces:
EventListener
- All Known Implementing Classes:
BeanValidator,DoubleRangeValidator,LengthValidator,LongRangeValidator,MethodExpressionValidator,RegexValidator,RequiredValidator
A Validator
implementation is a class that can perform validation (correctness
checks) on a EditableValueHolder. Zero
or more Validators can be associated with each EditableValueHolder in the view, and are
called during the Process Validations phase of the request
processing lifecycle.
Individual Validators should examine the value and
component that they are passed, and throw a ValidatorException
containing a FacesMessage, documenting
any failures to conform to the required rules.
For maximum generality, Validator instances may be
configurable based on properties of the Validator implementation
class. For example, a range check Validator might support
configuration of the minimum and maximum values to be used.
Validator implementations must have a zero-arguments
public constructor. In addition, if the Validator class
wishes to have configuration property values saved and restored with
the view, the implementation must also implement StateHolder.
If the class implementing
Validator has a ResourceDependency annotation, the action
described in ResourceDependency must be taken when
EditableValueHolder.addValidator(javax.faces.validator.Validator) is
called. If the class implementing Validator has a ResourceDependencies annotation, the
action described in ResourceDependencies must be taken
when EditableValueHolder.addValidator(javax.faces.validator.Validator)
is called.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidvalidate(FacesContext context, UIComponent component, Object value)
-
Field Details
-
NOT_IN_RANGE_MESSAGE_ID
Deprecated.The message identifier of the
FacesMessageto 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 a{0}placeholder, which will be replaced by the configured minimum value, and a{1}placeholder, which will be replaced by the configured maximum value.- See Also:
-
-
Method Details
-
validate
Perform the correctness checks implemented by this
Validatoragainst the specifiedUIComponent. If any violations are found, aValidatorExceptionwill be thrown containing theFacesMessagedescribing the failure.For a validator to be fully compliant with Version 2 and later of the specification, it must not fail validation on
nullor empty values unless it is specifically intended to addressnullor empty values. An application-wide<context-param>is provided to allow validators designed for JSF 1.2 to work with JSF 2 and later. Thejavax.faces.VALIDATE_EMPTY_FIELDS<context-param>must be set tofalseto enable this backwards compatibility behavior.- Parameters:
context- FacesContext for the request we are processingcomponent- UIComponent we are checking for correctnessvalue- the value to validate- Throws:
ValidatorException- if validation failsNullPointerException- ifcontextorcomponentisnull
-
DoubleRangeValidator.NOT_IN_RANGE_MESSAGE_IDorLongRangeValidator.NOT_IN_RANGE_MESSAGE_IDinstead.