Interface Validator<T>
-
- Type Parameters:
T- The generic type of object value to validate.
- All Superinterfaces:
EventListener
- All Known Implementing Classes:
BeanValidator,DoubleRangeValidator,LengthValidator,LongRangeValidator,MethodExpressionValidator,RegexValidator,RequiredValidator
public interface Validator<T> extends EventListener
A Validator implementation is a class that can perform validation (correctness checks) on a
EditableValueHolder. Zero or moreValidators can be associated with eachEditableValueHolderin 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 aValidatorExceptioncontaining aFacesMessage, documenting any failures to conform to the required rules.For maximum generality,
Validatorinstances may be configurable based on properties of theValidatorimplementation class. For example, a range checkValidatormight support configuration of the minimum and maximum values to be used.Validatorimplementations must have a zero-arguments public constructor. In addition, if theValidatorclass wishes to have configuration property values saved and restored with the view, the implementation must also implementStateHolder.If the class implementing
Validatorhas aResourceDependencyannotation, the action described inResourceDependencymust be taken whenEditableValueHolder.addValidator(jakarta.faces.validator.Validator)is called. If the class implementingValidatorhas aResourceDependenciesannotation, the action described inResourceDependenciesmust be taken whenEditableValueHolder.addValidator(jakarta.faces.validator.Validator)is called.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidvalidate(FacesContext context, UIComponent component, T value)
-
-
-
Method Detail
-
validate
void validate(FacesContext context, UIComponent component, T value) throws ValidatorException
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 Jakarta Faces 1.2 to work with Jakarta Faces 2 and later. Thejakarta.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
-
-