- java.lang.Object
- 
- org.omnifaces.validator.ValueChangeValidator<T>
 
- 
- All Implemented Interfaces:
- Validator<T>,- EventListener
 
 public abstract class ValueChangeValidator<T> extends Object implements Validator<T> By default, Faces validators run on every request, regardless of whether the submitted value has changed or not. In case of validation against the DB on complex objects which are already stored in the model in a broader scope, such as the view scope, this may result in unnecessarily expensive service/DAO calls. In such case, you'd like to perform the expensive service/DAO call only when the submitted value is really changed as compared to the model value. This validator offers you a template to do it transparently. To use it, just change your validators from: public class YourValidator implements Validator<YourEntity> { public void validate(FacesContext context, UIComponent component, YourEntity submittedValue) { // ... } }to public class YourValidator extends ValueChangeValidator<YourEntity> { public void validateChangedObject(FacesContext context, UIComponent component, YourEntity submittedValue) { // ... } }So, essentially, just replaceimplements Validatorbyextends ValueChangeValidatorand rename the method fromvalidatetovalidateChangedObject.- Since:
- 1.7
- Author:
- Juliano, Bauke Scholtz
 
- 
- 
Field Summary- 
Fields inherited from interface jakarta.faces.validator.ValidatorNOT_IN_RANGE_MESSAGE_ID
 
- 
 - 
Constructor SummaryConstructors Constructor Description ValueChangeValidator()
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidvalidate(FacesContext context, UIComponent component, T submittedValue)If the component is an instance ofEditableValueHolderand its old object value is equal to the submitted value, then return immediately from the method and don't perform any validation.abstract voidvalidateChangedObject(FacesContext context, UIComponent component, T submittedValue)Use this method instead ofvalidate(FacesContext, UIComponent, Object)if you intend to perform the validation only when the submitted value is really changed as compared to the model value.
 
- 
- 
- 
Method Detail- 
validatepublic void validate(FacesContext context, UIComponent component, T submittedValue) If the component is an instance ofEditableValueHolderand its old object value is equal to the submitted value, then return immediately from the method and don't perform any validation. Otherwise, invokevalidateChangedObject(FacesContext, UIComponent, Object)which may in turn do the necessary possibly expensive DAO operations.
 - 
validateChangedObjectpublic abstract void validateChangedObject(FacesContext context, UIComponent component, T submittedValue) Use this method instead ofvalidate(FacesContext, UIComponent, Object)if you intend to perform the validation only when the submitted value is really changed as compared to the model value.- Parameters:
- context- The involved faces context.
- component- The involved UI component.
- submittedValue- The submitted value.
 
 
- 
 
-