title: Springboot Validation Exception: org.springframework.validation.BeanPropertyBindingResult Exception
body: <p>I am trying to show validation errors in my form, but I am not able to implement it.
  I am trying to pass null values, I get the hibernate validation message but I am not able to see form validation?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>@RequestMapping(value = "/register", method = RequestMethod.POST)
      public String saveForm(@Valid Users users,Model model,Errors errors) {
          if(errors.hasErrors()) {
              return "registerPage";
          }
          else {
              model.addAttribute("message","Registered................");
          System.out.println("Save Users TEST------------------------------------&gt;");
          userRepository.save(users);
  
          return "register-success";
          }
  
  
      }
  </code></pre>
  
  <p>Here is the exception:</p>
  
  <blockquote>
    <p>Field error in object 'users' on field 'salary': rejected value
    [null]; codes
    [NotNull.users.salary,NotNull.salary,NotNull.java.lang.Integer,NotNull];
    arguments
    [org.springframework.context.support.DefaultMessageSourceResolvable:
    codes [users.salary,salary]; arguments []; default message [salary]];
    default message [must not be null] Field error in object 'users' on
    field 'dept': rejected value []; codes
    [Size.users.dept,Size.dept,Size.java.lang.String,Size]; arguments
    [org.springframework.context.support.DefaultMessageSourceResolvable:
    codes [users.dept,dept]; arguments []; default message [dept],10,2];
    default message [Length should be in between 2 to 10] Field error in
    object 'users' on field 'name': rejected value []; codes
    [Size.users.name,Size.name,Size.java.lang.String,Size]; arguments
    [org.springframework.context.support.DefaultMessageSourceResolvable:
    codes [users.name,name]; arguments []; default message [name],30,2];
    default message [Length should be in between 2 to 30]]</p>
  </blockquote>
  
  <p>Here is my User Pojo:</p>
  
  <pre><code>public class Users implements Serializable{
  
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      @Column(name="id")
      private Integer id;
      @Column(name="name")
      @NotNull
      @Size(min=2,max=30,message="Length should be in between 2 to 30")
      private String name;
  
      @Column(name="salary")
      @NotNull
      private Integer salary;
      @Column(name="dept")
      @NotNull
      @Size(min=2,max=10,message="Length should be in between 2 to 10")
      private String dept;
  
      ....
  
      }
  </code></pre>
  
  <p>Here is my html form(Using thymeleaf):</p>
  
  <pre><code>&lt;h1 th:text="${message}" align="center"&gt;&lt;/h1&gt;
  &lt;div class="container"&gt;
      &lt;h2&gt;Registration form&lt;/h2&gt;
        &lt;form class="form-horizontal" th:object="${registerCommand}" th:action="@{/rest/users/register}" method="post"&gt;
          &lt;div class="form-group"&gt;
              &lt;label for="name"&gt;Username:&lt;/label&gt;
               &lt;input type="text"
                  class="form-control" id="name" placeholder="Enter Name"
                  name="name" th:field="*{name}"&gt; &lt;br /&gt;
              &lt;p th:if="${#fields.hasErrors('name')}" th:errors="*{name}" th:field="*{name}"
                  class="alert alert-danger"&gt;&lt;/p&gt;
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
              &lt;label for="dept"&gt;Department:&lt;/label&gt;
               &lt;input type="text"
                  class="form-control" id="dept" placeholder="Enter Department"
                  name="dept" th:field="*{dept}"&gt; &lt;br /&gt;
              &lt;p th:if="${#fields.hasErrors('dept')}" th:errors="*{dept}" th:field="*{dept}"
                  class="alert alert-danger"&gt;&lt;/p&gt;
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
              &lt;label for="salary"&gt;Salary:&lt;/label&gt; &lt;input type="text"
                  class="form-control" id="salary" placeholder="Enter salary"
                  name="salary" th:field="*{salary}"&gt; &lt;br /&gt;
              &lt;p th:if="${#fields.hasErrors('salary')}" th:errors="*{salary}" th:field="*{salary}"
                  class="alert alert-danger"&gt;&lt;/p&gt;
          &lt;/div&gt;
  
          &lt;button type="submit" class="btn btn-sucess"&gt;Submit&lt;/button&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>