public abstract class ValueChangeValidator extends Object implements Validator
This validator offers you a template to do it transparently. To use it, just change your validators from:
public class YourValidator implements Validator { public void validate(FacesContext context, UIComponent component, Object submittedValue) { // ... } }
to
public class YourValidator extends ValueChangeValidator { public void validateChangedObject(FacesContext context, UIComponent component, Object submittedValue) { // ... } }So, essentially, just replace
implements Validator
by extends ValueChangeValidator
and
rename the method from validate
to validateChangedObject
.NOT_IN_RANGE_MESSAGE_ID
Constructor and Description |
---|
ValueChangeValidator() |
Modifier and Type | Method and Description |
---|---|
void |
validate(FacesContext context,
UIComponent component,
Object submittedValue)
If the component is an instance of
EditableValueHolder and its old object value is equal to the
submitted value, then return immediately from the method and don't perform any validation. |
abstract void |
validateChangedObject(FacesContext context,
UIComponent component,
Object submittedValue)
Use this method instead of
validate(FacesContext, UIComponent, Object) if you intend to perform the
validation only when the submitted value is really changed as compared to the model value. |
public void validate(FacesContext context, UIComponent component, Object submittedValue)
EditableValueHolder
and its old object value is equal to the
submitted value, then return immediately from the method and don't perform any validation. Otherwise, invoke
validateChangedObject(FacesContext, UIComponent, Object)
which may in turn do the necessary possibly
expensive DAO operations.public abstract void validateChangedObject(FacesContext context, UIComponent component, Object submittedValue)
validate(FacesContext, UIComponent, Object)
if you intend to perform the
validation only when the submitted value is really changed as compared to the model value.context
- The involved faces context.component
- The involved UI component.submittedValue
- The submitted value.