title: Spring 3 Form Validation is working for @NotNull but not working for @Size annotation
body: <p>I am facing a problem with Spring form validation.
  It works for @NotNull annotation but some how not working for @Size. I am attaching some code below. Thanks in advance.</p>
  
  <pre><code>    package com.doctor;
      import javax.validation.constraints.NotNull;
      import javax.validation.constraints.Size;
  
      public class Doctor 
      {
          @NotNull(message="Cannot be Null")
          private String uname;
  
  
          @Size(min=1,max=8,message="Min 1 and Max 8")
          private String password;
          private String doctor_fname,doctor_lname,address,dept_id,experience,email,phone,resume,image;
  
          public String getUname() {
              return uname;
          }
  
  
          public void setUname(String uname) {
              this.uname = uname;
          }
  
          public String getPassword() {
              return password;
          }
  
          public void setPassword(String password) {
              this.password = password;
          }
  ....................
  ...................
  </code></pre>
  
  <p>DoctorController</p>
  
  <pre><code>package com.doctor;
  import org.springframework.stereotype.Controller;
  import org.springframework.validation.BindingResult;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.ui.Model;
  import javax.validation.Valid;
  
  @Controller
  public class DoctorController {
  
  
      @RequestMapping(value="/registerDoctor", method=RequestMethod.GET)
      public String showRegisterForm(Model model) 
      {
          System.out.println("test");
          model.addAttribute(new Doctor());
          //return "register1";
          return "doctor/edit";
      }
      @RequestMapping(value="/registerDoctor", method=RequestMethod.POST)
      public String addDoctorformForm(@Valid Doctor doctor,BindingResult bindingresult) 
      {
          if(bindingresult.hasErrors())
          {
              return "doctor/edit";
  
          }
          else
          {               
              return "doctor/added";
          }
  
  
      }
  }
  </code></pre>
  
  <p>Display page</p>
  
  <pre><code>&lt;%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form"%&gt;
  
  
      &lt;h2&gt;Create a Doctor account&lt;/h2&gt;
      &lt;sf:form method="POST" modelAttribute="doctor"
          enctype="multipart/form-data"&gt;
          &lt;fieldset&gt;
              &lt;table&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;sf:label path="uname"&gt;User Name:&lt;/sf:label&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;sf:input path="uname"  /&gt;&lt;br /&gt; &lt;sf:errors
                              path="uname" /&gt; &lt;/td&gt; 
                  &lt;/tr&gt;
  
                  &lt;tr&gt;
                      &lt;td&gt;&lt;sf:label path="password"&gt;Password:&lt;/sf:label&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;sf:password path="password" showPassword="true" /&gt;
                          &lt;br /&gt; &lt;sf:errors
                              path="password" /&gt;&lt;/td&gt;
                  &lt;/tr&gt;
  
                  &lt;tr&gt;
                      &lt;td&gt;&lt;sf:label path="doctor_fname"&gt;First Name:&lt;/sf:label&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;sf:input path="doctor_fname" size="15" /&gt;&lt;br /&gt; &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;sf:label path="doctor_lname"&gt;Last Name:&lt;/sf:label&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;sf:input path="doctor_lname" size="15" /&gt;&lt;br /&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;sf:label path="address"&gt;Address:&lt;/sf:label&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;sf:input path="address" size="15" /&gt;&lt;br /&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;sf:label path="dept_id"&gt;Department:&lt;/sf:label&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;sf:input path="dept_id" size="15" /&gt;&lt;br /&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;sf:label path="experience"&gt;Experience:&lt;/sf:label&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;sf:input path="experience" size="15" /&gt;&lt;br /&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;sf:label path="email"&gt;Email Address:&lt;/sf:label&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;sf:input path="email" size="30" /&gt; &lt;small&gt;In case
                              you forget something&lt;/small&gt;&lt;br /&gt; &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;sf:label path="phone"&gt;Phone:&lt;/sf:label&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;sf:input path="phone" size="30" /&gt; &lt;small&gt;In case
                              you forget something&lt;/small&gt;&lt;br /&gt; &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;label for="resume"&gt;Resume:&lt;/label&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;input name="resume" type="file" /&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;label for="image"&gt;Profile image:&lt;/label&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;input name="image" type="file" /&gt;
                  &lt;/tr&gt;
  
                  &lt;tr&gt;
                      &lt;th&gt;&lt;/th&gt;
                      &lt;td&gt;&lt;input name="commit" type="submit"&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
          &lt;/fieldset&gt;
      &lt;/sf:form&gt;
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/aquOV.png" alt="Output"></p>
  
  <p>I don't understand why @Size for password is not working.</p>
  
  <p>Help will be highly appreciated.</p>