Reputation: 1788
I have a Spring-based web form (Web Flow actually) that I need to modify.
The form has multiple elements that are validated server-side. The tricky part is, the whole form is optional - if the user just clicks past it, I'm supposed to quietly ignore the whole thing.
How can I do this?
Upvotes: 1
Views: 713
Reputation: 120831
I assume you use JSR303 Bean Validation. But the solution depends strongly on what you exactly mean by "the whole form is optional",
do you mean each value is independent optional: ----
The most validation rules are designed to accept Null Values (except you explicite permit Nulls (@NotNull
, @NotEmpty
) - maybe this would be enough for your probelm.
do you mean that the whole form needs to be valid, if at least one value is set: ---- JSR303 Bean Validation knows the concept of validation groups: A rule gets only validated if its validation group is requested to be validated (All not explicit assigned validation rules belong the the default group). You can use this to design a validation group for your optional values, and then start the valdation for this group explicite only when at least one of its values is set. This can be done by implementing a custom DefaultGroupSequenceProvider for the form. 5.4.2. @GroupSequenceProvider
Upvotes: 1