Top Description Fields Methods
javax.faces.validator

public Interface Validator<T>

extends EventListener
Known Direct Implementers
com.sun.faces.cdi.CdiValidator, com.sun.faces.ext.component.WholeBeanValidator, com.sun.faces.ext.validator.CreditCardValidator, com.sun.faces.taglib.jsf_core.ValidatorTag.BindingValidator, javax.faces.component.MethodBindingValidator, javax.faces.validator.BeanValidator, javax.faces.validator.DoubleRangeValidator, javax.faces.validator.LengthValidator, javax.faces.validator.LongRangeValidator, javax.faces.validator.MethodExpressionValidator, javax.faces.validator.RegexValidator, javax.faces.validator.RequiredValidator
Type Parameters
<T>
The generic type of object value to validate.
Imports
javax.faces.component.UIComponent, javax.faces.context.FacesContext, java.util.EventListener

A Validator implementation is a class that can perform validation (correctness checks) on a javax.faces.component.EditableValueHolder. Zero or more Validators can be associated with each javax.faces.component.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 javax.faces.application.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 javax.faces.component.StateHolder.

If the class implementing Validator has a javax.faces.application.ResourceDependency annotation, the action described in ResourceDependency must be taken when javax.faces.component.EditableValueHolder#addValidator is called. If the class implementing Validator has a javax.faces.application.ResourceDependencies annotation, the action described in ResourceDependencies must be taken when javax.faces.component.EditableValueHolder#addValidator is called.

Field Summary

Modifier and TypeField and Description
public static final String
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.

Method Summary

Modifier and TypeMethod and Description
public void
validate(FacesContext
FacesContext for the request we are processing
context
,
UIComponent
UIComponent we are checking for correctness
component
,
T
the value to validate
value
)

Perform the correctness checks implemented by this Validator against the specified UIComponent.

Field Detail

NOT_IN_RANGE_MESSAGE_IDback to summary
public static final String 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 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.

Method Detail

validateback to summary
public 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 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:T

the value to validate

Exceptions
ValidatorException:
if validation fails
NullPointerException:
if context or component is null