T
- The generic type of object value to validate.public interface Validator<T>
extends java.util.EventListener
A Validator implementation is a class that can perform validation
(correctness checks) on a EditableValueHolder
. Zero or more Validator
s
can be associated with each EditableValueHolder
in the view, and are called during
the Process Validations phase of the request processing lifecycle.
Individual Validator
s 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(jakarta.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(jakarta.faces.validator.Validator)
is called.
Modifier and Type | Method and Description |
---|---|
void |
validate(FacesContext context,
UIComponent component,
T value)
|
void validate(FacesContext context, UIComponent component, T value) throws ValidatorException
Perform the correctness checks implemented by this Validator
against the specified UIComponent
. If any violations are found, a ValidatorException
will be thrown
containing the 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.
context
- FacesContext for the request we are processingcomponent
- UIComponent we are checking for correctnessvalue
- the value to validateValidatorException
- if validation failsjava.lang.NullPointerException
- if context
or component
is null