Input data validation is a critical piece of functionality in any web application because we cannot always rely on users to enter valid data. We need to safeguard our data-stores and business processes against both malformed as well as malicious data.
Based on my experience with Spring, I thought of writing a series of tutorials on different methods of validating form input when working with Spring MVC.
This is the first part of that series, and I will be focusing on basic form data (i.e. data submitted by the user) validation in Spring MVC 3 using declarative annotations. In the future, I am hoping to touch on more advanced topics such as:
- Displaying custom messages for validation errors
- Writing custom annotations to validate view models (or fields)
- Using JSR 303 groups to perform conditional validations
- Validation using Spring’s Validator interface
- Comparison of different validation methods in Spring MVC (pros, cons and when to use them)
Hopefully by the end of the series, you will have a good idea about Spring validation mechanisms, and be able to pick the best option(s) for a particular problem.
Continue on to learn how to perform basic annotation-based validations in your Spring MVC 3.x web applications.