I am currently adding validation to a form. There are two things to check: The correctness of the value itself (e.g. if it is a positive integer or valid email) and whether all required fields were filled in.
However, if by some means (f:ajax
or IceFaces partialSubmit
attribute) I make the validation for type correctness happen at once (e.g. when the field loses focus), it will also check the required
attribute in this same step. In most cases this is no problem, as the user already entered a value and is likely to correct it rather than go back to a blank field.
However, in the case where he actually wants to clear the field again, he can no longer do so without getting an error. In consequence, I only want to check the required-ness of fields on finally submitting the page.
At the moment, my only idea to separate the two validation types is by performing all required-checks in the backing beans action method, thus tying it to directly to the final submit via button.
Is there another way?
(For background: The reason why one might want to clear the field again is that requirements can change depending on other selections in the form. So one might decide to not provide this field after all and only after that correct the option that actually makes this field optional.)