Book Image

Spring MVC Beginner's Guide

By : Amuthan Ganeshan
Book Image

Spring MVC Beginner's Guide

By: Amuthan Ganeshan

Overview of this book

Table of Contents (19 chapters)
Spring MVC Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – combining Spring and bean validations


You need to write the previous bean validations again in a classic Spring-based validation, which is not a good idea, but thanks to the flexibility and extensibility of Spring validation, you can combine both a Spring-based validation and bean validation together with a little extra code. Perform the following steps:

  1. Create a class called ProductValidator under the com.packt.webstore.validator package in the source folder src/main/java. Then, add the following code into it:

    package com.packt.webstore.validator;
    
    import java.util.HashSet;
    import java.util.Set;
    import javax.validation.ConstraintViolation;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.validation.Errors;
    import org.springframework.validation.Validator;
    import com.packt.webstore.domain.Product;
    
    public class ProductValidator implements Validator{
    
      @Autowired
      private javax.validation.Validator beanValidator;
    
      private Set&lt...