Learn Java for Web Development

(Tina Meador) #1
CHAPTER 5: Building Java Web Applications with Spring Web MVC 257

Annotations-Based Validation

The following section demonstrates how you can validate the user-entered data using annotations.
Figure 5-22 illustrates the modified files and newly added files in the application.


Listing 5-50 illustrates the BookValidator.


Listing 5-50. Validations in the BookValidator



  1. package com.apress.bookstore.validator;



  2. import org.springframework.validation.Errors;

  3. import org.springframework.validation.ValidationUtils;

  4. import org.springframework.validation.Validator;




Figure 5-22. Modified files and new files in the directory structure for annotations-based validation

Free download pdf