The following error occurred validating the
Of course, there are more error conditions left for you to add.
I was able to validate 7 error conditions and raise a different runtime error for each condition.
Gradle: All of the validations used above are part of the JSR-303 API, except for “Not Empty” and “Email”, which are Hibernate-Validator annotations. Now, let’s tell our controller to validate the form in the submission handler method: Simply adding `@Valid` tells Spring to validate the “Subscriber” object. The Binding Result must come right after the model object that is validated or else Spring will fail to validate the object and throw an exception.
Let’s take a look at how to do that with a text field that is only supposed to have a value of either ‘AAAA’ or ‘BBBB’ (yes, I know that this does not make much sense in a real PDF form).
So, if the user enters ‘01234’ we should see an error message that would instruct the user about what type of data is valid for this field.
Prerequisites: You should have a basic understanding of how to submit forms using Spring MVC.
If you do not already understand Spring MVC basics, follow some of my other Spring tutorials first. To get started, we first need a couple JARs in our classpath.