Top Description Inners Fields Constructors Methods
jakarta.faces.validator

public Class BeanValidator

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
Static Imports
jakarta.faces.validator.MessageFactory.getLabel, .MessageFactory.getMessage, .MultiFieldValidationUtils.FAILED_FIELD_LEVEL_VALIDATION, .MultiFieldValidationUtils.getMultiFieldValidationCandidates, .MultiFieldValidationUtils.wholeBeanValidationEnabled

A Validator that delegates validation of the bean property to the Bean Validation API.

Since
2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private transient Class<?>[]
public static final String
DISABLE_DEFAULT_BEAN_VALIDATOR_PARAM_NAME

If this param is defined, and calling toLowerCase().equals(“true”) on a String representation of its value returns true, the runtime must not automatically add the validator with validator-id equal to the value of the symbolic constant VALIDATOR_ID to the list of default validators.

public static final String
EMPTY_VALIDATION_GROUPS_PATTERN

The regular expression pattern that identifies an empty list of validation groups.

public static final String
ENABLE_VALIDATE_WHOLE_BEAN_PARAM_NAME

If this param is set, and calling toLowerCase().equals("true") on a String representation of its value returns true take the additional actions relating to <validateWholeBean /> specified in validate.

private boolean
private static final Logger
public static final String
MESSAGE_ID

The message identifier of the jakarta.faces.application.FacesMessage to be created if a constraint failure is found.

private boolean
public static final String
VALIDATION_GROUPS_DELIMITER

The delimiter that is used to separate the list of fully-qualified group names as strings.

private String
public static final String
VALIDATOR_FACTORY_KEY

The name of the Jakarta Servlet context attribute which holds the object used by Jakarta Faces to obtain Validator instances.

public static final String
VALIDATOR_ID

The standard validator id for this validator, as defined by the Jakarta Server Face specification.

Constructor Summary

AccessConstructor and Description
public

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 Validator
public String

Returns:

the value of the validatinGroups attribute.
getValidationGroups
()

Return the validation groups passed to the Validation API when checking constraints.

private static ValidatorFactory
private static ValueReference
getValueReference(FacesContext context, UIComponent component, ValueExpression valueExpression)

public boolean
initialStateMarked()

Implements jakarta.faces.component.PartialStateHolder.initialStateMarked.

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

private boolean
isResolvable(ValueReference valueReference, ValueExpression valueExpression)

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.

private Class<?>[]
parseValidationGroups(String validationGroupsStr)

private void
recordValidationResult(FacesContext context, UIComponent component, Object wholeBean, String propertyName, Object propertyValue)

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
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.

public void
setValidationGroups(String
comma-separated list of validation groups (string with only spaces and commas treated as null)
validationGroups
)

A comma-separated list of validation groups which are used to filter which validations get checked by this validator.

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.

Verify that the value is valid according to the Bean Validation constraints.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cachedValidationGroupsback to summary
private transient Class<?>[] cachedValidationGroups
DISABLE_DEFAULT_BEAN_VALIDATOR_PARAM_NAMEback to summary
public static final String DISABLE_DEFAULT_BEAN_VALIDATOR_PARAM_NAME

If this param is defined, and calling toLowerCase().equals(“true”) on a String representation of its value returns true, the runtime must not automatically add the validator with validator-id equal to the value of the symbolic constant VALIDATOR_ID to the list of default validators. Setting this parameter to true will have the effect of disabling the automatic installation of Bean Validation to every input component in every view in the application, though manual installation is still possible.

EMPTY_VALIDATION_GROUPS_PATTERNback to summary
public static final String EMPTY_VALIDATION_GROUPS_PATTERN

The regular expression pattern that identifies an empty list of validation groups.

ENABLE_VALIDATE_WHOLE_BEAN_PARAM_NAMEback to summary
public static final String ENABLE_VALIDATE_WHOLE_BEAN_PARAM_NAME

If this param is set, and calling toLowerCase().equals("true") on a String representation of its value returns true take the additional actions relating to <validateWholeBean /> specified in validate.

Since
2.3
initialStateback to summary
private boolean initialState
LOGGERback to summary
private static final Logger LOGGER
MESSAGE_IDback to summary
public static final String MESSAGE_ID

The message identifier of the jakarta.faces.application.FacesMessage to be created if a constraint failure is found. The message format string for this message may optionally include the following placeholders:

  • {0} replaced by the interpolated message from Bean Validation.
  • {1} replaced by a String whose value is the label of the input component that produced this message.

The message format string provided by the default implementation should be a the placeholder {0}, thus fully delegating the message handling to Bean Validation. A developer can override this message format string to make it conform to other Jakarta Server Face validator messages (i.e., by including the component label)

transientValueback to summary
private boolean transientValue
VALIDATION_GROUPS_DELIMITERback to summary
public static final String VALIDATION_GROUPS_DELIMITER

The delimiter that is used to separate the list of fully-qualified group names as strings.

validationGroupsback to summary
private String validationGroups
VALIDATOR_FACTORY_KEYback to summary
public static final String VALIDATOR_FACTORY_KEY

The name of the Jakarta Servlet context attribute which holds the object used by Jakarta Faces to obtain Validator instances. If the Jakarta Servlet context attribute is missing or contains a null value, Jakarta Server Faces is free to use this Jakarta Servlet context attribute to store the ValidatorFactory bootstrapped by this validator.

VALIDATOR_IDback to summary
public static final String VALIDATOR_ID

The standard validator id for this validator, as defined by the Jakarta Server Face specification.

Constructor Detail

BeanValidatorback to summary
public BeanValidator()

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
getBeanValidatorback to summary
private static Validator getBeanValidator(FacesContext context)
getValidationGroupsback to summary
public String getValidationGroups()

Return the validation groups passed to the Validation API when checking constraints. If the validationGroupsArray attribute is omitted or empty, the validation groups will be inherited from the branch defaults, or if there are no branch defaults, the jakarta.validation.groups.Default group will be used.

Returns:String

the value of the validatinGroups attribute.

getValidatorFactoryback to summary
private static ValidatorFactory getValidatorFactory(FacesContext context)
getValueReferenceback to summary
private static ValueReference getValueReference(FacesContext context, UIComponent component, ValueExpression valueExpression)
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
isResolvableback to summary
private boolean isResolvable(ValueReference valueReference, ValueExpression valueExpression)
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
parseValidationGroupsback to summary
private Class<?>[] parseValidationGroups(String validationGroupsStr)
recordValidationResultback to summary
private void recordValidationResult(FacesContext context, UIComponent component, Object wholeBean, String propertyName, Object propertyValue)
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
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
setValidationGroupsback to summary
public void setValidationGroups(String validationGroups)

A comma-separated list of validation groups which are used to filter which validations get checked by this validator. If the validationGroupsArray attribute is omitted or is empty, the validation groups will be inherited from the branch defaults or, if there are no branch defaults, the jakarta.validation.groups.Default group will be used.

Parameters
validationGroups:String

comma-separated list of validation groups (string with only spaces and commas treated as null)

validateback to summary
public void validate(FacesContext context, UIComponent component, Object value)

Implements jakarta.faces.validator.Validator.validate.

Verify that the value is valid according to the Bean Validation constraints.

Obtain a ValidatorFactory instance by calling jakarta.validation.Validation#buildDefaultValidatorFactory.

Let validationGroupsArray be a Class [] representing validator groups set on the component by the tag handler for this validator. The first search component terminates the search for the validation groups value. If no such value is found use the class name of jakarta.validation.groups.Default as the value of the validation groups.

Let valueExpression be the return from calling UIComponent#getValueExpression on the argument component, passing the literal string “value” (without the quotes) as an argument. If this application is running in an environment with Jakarta Expression Language, obtain the ValueReference from valueExpression and let valueBaseClase be the return from calling ValueReference.getBase() and valueProperty be the return from calling ValueReference.getProperty(). If an earlier version of Jakarta Expression Language is present, use the appropriate methods to inspect valueExpression and derive values for valueBaseClass and valueProperty.

If no ValueReference can be obtained, take no action and return.

If ValueReference.getBase() return null, take no action and return.

Obtain the ValidatorContext from the ValidatorFactory.

Decorate the MessageInterpolator returned from ValidatorFactory#getMessageInterpolator with one that leverages the Locale returned from jakarta.faces.component.UIViewRoot#getLocale, and store it in the ValidatorContext using ValidatorContext#messageInterpolator.

Obtain the jakarta.validation.Validator instance from the validatorContext.

Obtain a jakarta.validation.BeanDescriptor from the jakarta.validation.Validator. If hasConstraints() on the BeanDescriptor returns false, take no action and return. Otherwise proceed.

Call jakarta.validation.Validator#validateValue, passing valueBaseClass, valueProperty, the value argument, and validatorGroupsArray as arguments.

If the returned Set<ConstraintViolation> is non-empty, for each element in the Set, create a FacesMessage where the summary and detail are the return from calling ConstraintViolation#getMessage. Capture all such FacesMessage instances into a Collection and pass them to ValidatorException#ValidatorException(java.util.Collection). If the ENABLE_VALIDATE_WHOLE_BEAN_PARAM_NAME application parameter is enabled and this Validator instance has validation groups other than or in addition to the Default group, record the fact that this field failed validation so that any <f:validateWholeBean /> component later in the tree is able to skip class-level validation for the bean for which this particular field is a property. Regardless of whether or not ENABLE_VALIDATE_WHOLE_BEAN_PARAM_NAME is set, throw the new exception.

If the returned Set is empty, the ENABLE_VALIDATE_WHOLE_BEAN_PARAM_NAME application parameter is enabled and this Validator instance has validation groups other than or in addition to the Default group, record the fact that this field passed validation so that any <f:validateWholeBean /> component later in the tree is able to allow class-level validation for the bean for which this particular field is a property.

Parameters
context:FacesContext

Doc from jakarta.faces.validator.Validator.validate.

FacesContext for the request we are processing

component:UIComponent

Doc from jakarta.faces.validator.Validator.validate.

UIComponent we are checking for correctness

value:Object

Doc from jakarta.faces.validator.Validator.validate.

the value to validate

Annotations
@Override
Exceptions
ValidatorException:
if validation fails
jakarta.faces.validator back to summary

private Class BeanValidator.FacesAwareMessageInterpolator

extends Object
implements MessageInterpolator
Class Inheritance
  • java.lang.Object
  • jakarta.faces.validator.BeanValidator.FacesAwareMessageInterpolator
All Implemented Interfaces
jakarta.validation.MessageInterpolator

Field Summary

Modifier and TypeField and Description
private FacesContext
private MessageInterpolator

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String
interpolate(String
the message to interpolate
message
,
MessageInterpolator.Context
contextual information related to the interpolation
context
)

Implements jakarta.validation.MessageInterpolator.interpolate.

Interpolates the message template based on the constraint validation context.
public String
interpolate(String
the message to interpolate
message
,
MessageInterpolator.Context
contextual information related to the interpolation
context
,
Locale
the locale targeted for the message
locale
)

Implements jakarta.validation.MessageInterpolator.interpolate.

Interpolates the message template based on the constraint validation context.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contextback to summary
private FacesContext context
delegateback to summary
private MessageInterpolator delegate

Constructor Detail

FacesAwareMessageInterpolatorback to summary
public FacesAwareMessageInterpolator(FacesContext context, MessageInterpolator delegate)

Method Detail

interpolateback to summary
public String interpolate(String message, MessageInterpolator.Context context)

Implements jakarta.validation.MessageInterpolator.interpolate.

Doc from jakarta.validation.MessageInterpolator.interpolate.

Interpolates the message template based on the constraint validation context.

The locale is defaulted according to the MessageInterpolator implementation. See the implementation documentation for more detail.

Parameters
message:String

the message to interpolate

context:MessageInterpolator.Context

contextual information related to the interpolation

Returns:String

interpolated error message

Annotations
@Override
interpolateback to summary
public String interpolate(String message, MessageInterpolator.Context context, Locale locale)

Implements jakarta.validation.MessageInterpolator.interpolate.

Doc from jakarta.validation.MessageInterpolator.interpolate.

Interpolates the message template based on the constraint validation context. The Locale used is provided as a parameter.

Parameters
message:String

the message to interpolate

context:MessageInterpolator.Context

contextual information related to the interpolation

locale:Locale

the locale targeted for the message

Returns:String

interpolated error message

Annotations
@Override