title: @Valid annotation is not working in my spring MVC maven project
body: <p>I am trying to validate my JSP page field length using @Valid and @Size annotations, but they were not worked. My I know what I am missing?</p>
  
  <p>Please find my below code.</p>
  
  <p><strong>Student.java (pojo class)</strong></p>
  
  <pre><code>package com.vijay.controllerCAMVC;
  
  import java.util.ArrayList;
  import java.util.Date;
  
  import javax.validation.Valid;
  import javax.validation.constraints.NotNull;
  import javax.validation.constraints.Size;
  
  import jdk.nashorn.internal.objects.annotations.SpecializedFunction;
  
  public class Student {
  
      @Size(min=2, max=20)
      private String firstname;
  
  //    @Size(min=2, max=20, message='Size.student1.lastname')
      **@Size(min=2, max=20)** 
  //    , message="Please enter lastname length between {min} and {max}") 
      private String lastname;
  
      private Date dateofbirth;
      private ArrayList&lt;String&gt; courses;
  
      private Address address;
  
      public Date getDateofbirth() {
          return dateofbirth;
      }
      public void setDateofbirth(Date string) {
          this.dateofbirth = string;
      }
      public ArrayList&lt;String&gt; getCourses() {
          return courses;
      }
      public void setCourses(ArrayList&lt;String&gt; courses) {
          this.courses = courses;
      }
  
  
      public String getFirstname() {
          return firstname;
      }
      public void setFirstname(String firstname) {
          this.firstname = firstname;
      }
      public String getLastname() {
          return lastname;
      }
      public void setLastname(String lastname) {
          this.lastname = lastname;
      }
  
  
      public Address getAddress() {
          return address;
      }
      public void setAddress(Address address) {
          this.address = address;
      }
  
  
  
  }
  </code></pre>
  
  <p><strong>Controller class code :</strong></p>
  
  <pre><code>package com.vijay.controllerCAMVC;
  
  import java.beans.PropertyEditor;
  import java.text.DateFormat;
  import java.text.ParseException;
  import java.text.SimpleDateFormat;
  import java.util.Date;
  import java.util.Map;
  
  import javax.validation.Valid;
  
  import org.springframework.beans.propertyeditors.CustomDateEditor;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.validation.BindingResult;
  import org.springframework.web.bind.WebDataBinder;
  import org.springframework.web.bind.annotation.InitBinder;
  import org.springframework.web.bind.annotation.ModelAttribute;
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RequestParam;
  import org.springframework.web.servlet.ModelAndView;
  
  @Controller
  public class HelloWorld2 {
  
  
  //  avoiding binding of problem fields @ModelAttribute auto binding case, always in 1st position in controller
      @InitBinder
      public void initbinder( WebDataBinder webdatabinder){
          webdatabinder.setDisallowedFields( new String[] {"courses"} );
  //      property editors
          SimpleDateFormat df = new SimpleDateFormat("mm-dd-yyyy");
          webdatabinder.registerCustomEditor(Date.class, "dateofbirth", new CustomDateEditor(df, false) );
  
  //      String editor for custom property editors defined by user specific i.e StringPropertyEditor.java
          webdatabinder.registerCustomEditor(String.class, "firstname", new StringPropertyEditor() );
      }
  
  
      @SuppressWarnings({ "deprecation", "deprecation" })
      @RequestMapping(value = "/Submissionform.html", params = "DELETE", method = RequestMethod.POST)
      public ModelAndView modelview3(
              /*
               * @RequestParam(name = "firstname", required = false, defaultValue
               * = "ENter Name") String firstname,
               * 
               * @RequestParam(name = "lastname", required = false, defaultValue =
               * "Default2") String lastname
               */
              // @RequestParam Map&lt;String, String&gt; reqparams) {
  
  //      @Valid  Before do data binding from JSP to model please apply validations using annotations
          **@Valid**  @ModelAttribute("student1") Student student1, BindingResult result) {
          // similar to move corresponding using name
  
          if (result.hasErrors()) {
              ModelAndView modelandview = new ModelAndView("ApplicationForm");
              return modelandview;
          }
  
          ModelAndView modelandview = new ModelAndView("DeleteForm");
  
          // modelandview.addObject("msg", "Congratulation on Applicaiton
          // Submission for");
  
          // Student student1 = new Student();
          // student1.setFirstname(reqparams.get("firstname"));
          // student1.setLastname(reqparams.get("lastname"));
          //
          // DateFormat df = new SimpleDateFormat("dd/mm/yyy");
          // Date dateofbirth = null;
          //
          // try {
          // dateofbirth = (Date) df.parse(reqparams.get("dateofbirth"));
          // } catch (ParseException e) {
          // e.printStackTrace();
          // }
          // student1.setDateofbirth(dateofbirth);
          // modelandview.addObject("student1", student1);
          //
  
          return modelandview;
      }
  
      // common attributes which gets auto added to all methods in controller &amp;
      // executes 1st
      @ModelAttribute
      public void addcommonmodelattributes(Model model1) {
          model1.addAttribute("msg", "Congratulation on Applicaiton Submission for");
      }
  }
  </code></pre>
  
  <p>my JSP file:<strong>strong text</strong></p>
  
  <pre><code>&lt;%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %&gt;
  &lt;%-- page language="java" contentType="text/html; charset=ISO-8859-1" --%&gt;
  &lt;%--    pageEncoding="ISO-8859-1"%&gt; --%&gt;
  &lt;!-- &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; --&gt;
  &lt;html&gt;
  
  &lt;body&gt;
      &lt;h1&gt;Student Application Form&lt;/h1&gt;
  
  &lt;form:errors path="student1.*"/&gt;
  
      &lt;form action="/SimpleSpringMVC2/Submissionform.html" method="post"&gt;
  
  &lt;table&gt;
  &lt;tr&gt;
  &lt;td&gt; First Name : &lt;/td&gt; &lt;td&gt; &lt;input name="firstname" type="text" /&gt; &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td&gt; Last Name : &lt;/td&gt; &lt;td&gt; &lt;input name="lastname" type="text" /&gt; &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td&gt; Date of birth : &lt;/td&gt; &lt;td&gt; &lt;input name="dateofbirth" type="text" class="date" /&gt;
  ' &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td&gt; Courses : &lt;/td&gt; &lt;td&gt;  &lt;select name="courses" multiple&gt;
                  &lt;option value="C"&gt;C&lt;/option&gt;
                  &lt;option value="C++"&gt;C++&lt;/option&gt;
                  &lt;option value="Java"&gt;Java&lt;/option&gt;
              &lt;/select&gt; &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;/table&gt;
  
  &lt;table&gt;
  &lt;tr&gt;
  &lt;td&gt;City : &lt;/td&gt; &lt;td&gt;&lt;input type="text" name="address.city"&gt;&lt;/td&gt;
  &lt;td&gt;State : &lt;/td&gt; &lt;td&gt;&lt;input type="text" name="address.state"&gt;&lt;/td&gt;
  &lt;td&gt;PinCode : &lt;/td&gt; &lt;td&gt;&lt;input type="text" name="address.picode"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  
          &lt;input type="submit" name="CREATE" value="CREATE" /&gt; 
          &lt;input type="submit" name="MODIFY" value="MODIFY" /&gt; 
          &lt;input type="submit" name="DELETE" value="DELETE" /&gt;
  
      &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>