I know I can get the old value through UIInput#getValue().
But in many cases where the field is bound to a bean value I want to get the default value that I don’t need to validate if the input equals the default value.
This is very usefull if a certain field has a unique constraint and you have a editing form.
Validation will always fail since in a check constraint method it will always find its own value thus validating to false.
One way would be to pass that default value as an attribute using <f:attribute> and check inside the validator. But is there an easier built-in way?
The submitted value is just available as
valueargument in thevalidate()implementation.An alternative is to design the
Validatoras aValueChangeListener. It’ll then only be invoked when the value has really changed. It’s somewhat hacky, but it does the job you really need.or
with
Note that you cannot throw a
ValidatorExceptionthere, that’s why need to manually set both the component and faces context to invalid and manually add the message for the component. Thecontext.validationFailed()will force JSF to skip the update model values and invoke action phases.