1

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?

1
  • By not adding errors on null or empty values during validation? Commented Feb 14, 2014 at 19:12

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

It is the second option. I'll check into validation groups. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.