Hello,
I’m going to explain my need and problems i have :
I have 2 fields in a form.
Those 2 fields are not required but if no one is set, i want to display both of them in error.
My validation is done on blur events.
Here is my algorithm :
- blur on a field without any text in it (length : 0)
- validation autoexecuted by BlurListener : isValid ==> my field has a custom validator. This validator allows to validate many fields (kind of ValidIfAnotherFieldsValidatorsAreValid)
- the method isValid of AbstractField check if my field is empty then if it is required before launching validators. As it isn’t required, it doesn’t execute validation after.
I understand why the AbstractField manage isValid method like this (as explained here : http://dev.vaadin.com/ticket/2817)
But in my need, i would like to override those mecanism with a property like : setExecuteValidatorIfNull(boolean).
By this feature, i would be able to tell AbstractField to do this mecanism instead :
public boolean isValid() {
if (isEmpty()) {
if (isRequired()) {
return false;
} else {
/* PILEROU NEW CODE */
if(! getExecuteValidatorIfNull() ) {
return true;
}
/* PILEROU END OF NEW CODE */
}
}
if (validators == null) {
return true;
}
final Object value = getValue();
for (final Iterator<Validator> i = validators.iterator(); i.hasNext();) {
if (!(i.next()).isValid(value)) {
return false;
}
}
return true;
}
I haven’t seen another way to do what i want to do.
Is there another tip ?