title: Error message not showing in view page in JSR303, using Bootstrap in jsp
body: <p>I am adding server side validation in my project. and somehow the error message from controller is not reaching view page.
  I am using :</p>
  
  <p>spring
  jpa,
  JSR303 for validation, and 
  bootstrap</p>
  
  <p>Below is code for add.jsp </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  
  &lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%&gt;
  &lt;%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%&gt;
  
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  
  &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
  
  &lt;link rel="stylesheet"
      href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"&gt;
  &lt;script
      src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script
      src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"&gt;&lt;/script&gt;
  
  &lt;style&gt;
  .error {
      color: #ff0000;
  }
  
  .errorblock {
      color: #000;
      background-color: #ffEEEE;
      border: 3px solid #ff0000;
      padding: 8px;
      margin: 16px;
  }
  &lt;/style&gt;
  
  &lt;title&gt;Add User&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
      &lt;div class="container"&gt;
          &lt;div class="row"&gt;
              &lt;div class="col-md-12"&gt;
                  &lt;div class="col-md-4"&gt;
                      &lt;h2&gt;Add User&lt;/h2&gt;
                      &lt;form:form action="user" method="post" role="form"
                          commandName="user"&gt;
                          &lt;form:errors path="*" cssClass="errorblock" /&gt;
  
                          &lt;div class="form-group "&gt;
                              &lt;label for="user"&gt;User Name:&lt;/label&gt;
  
                              &lt;form:input type="text" class="form-control" path="name"
                                  id="name" placeholder="Enter User Name" required="requried"/&gt;
  
                          &lt;/div&gt;
  
  
                          &lt;div class="form-group"&gt;
                              &lt;label for="email"&gt;Email Address:&lt;/label&gt;
                              &lt;form:input type="email" path="emailAddress" class="form-control"
                                  id="email" placeholder="Enter Email Address" required="requried"/&gt;
  
                          &lt;/div&gt;
  
                          &lt;div class="form-group"&gt;
                              &lt;label for="role"&gt;Role:&lt;/label&gt;
                              &lt;form:select path="role" class="form-control" id="role" required="requried"&gt;
                                  &lt;option disabled selected&gt;&lt;/option&gt;
                                  &lt;c:forEach var="role" items="${roles}"&gt;
                                      &lt;option value="${role.value}"&gt;${role.name}&lt;/option&gt;
                                  &lt;/c:forEach&gt;
                              &lt;/form:select&gt;
  
                          &lt;/div&gt;
  
                          &lt;button type="submit" value="Submit" name="add"
                              class="btn btn-info active"&gt;Submit&lt;/button&gt;
                          &lt;a href="adminHome" class="btn btn-info" role="button"&gt;Back&lt;/a&gt;
  
                      &lt;/form:form&gt;
  
  
                  &lt;/div&gt;
                  &lt;div class="col-md-4"&gt;
                      &lt;div class="col-md-4"&gt;&lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Below is code for Controller.java</p>
  
  <pre><code>@RequestMapping(value = "/user", params = "add", method = RequestMethod.GET)
      public String getAddUser(Model model) {
          ArrayList&lt;Role&gt; roles = new ArrayList&lt;Role&gt;();
  
          // From user Add only admin and head of department can be added
          roles.add(Role.ADMIN);
          roles.add(Role.HEAD_OF_DEPARTMENT);
          model.addAttribute("roles", roles);
          model.addAttribute("user", new User());
          return "user/add";
      }
  
      @RequestMapping(value = "/user", params = "add", method = RequestMethod.POST)
      public String postAddUser(@ModelAttribute @Valid User user,
              BindingResult result) {
  
          if (result.hasErrors()) {
              return "redirect:user?add";
          } else {
              System.out.println("Inside postAddUser");
              user = userRepository.save(user);
              return "redirect:user?id=" + user.getId();
          }
  
      }
  </code></pre>
  
  <p>Below is code for User.java</p>
  
  <pre><code>package in.ac.jmi.entities;
  
  import in.ac.jmi.constants.Role;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.Table;
  import javax.validation.constraints.NotNull;
  
  import org.hibernate.validator.constraints.NotBlank;
  import org.hibernate.validator.constraints.NotEmpty;
  
  @Entity
  @Table(name="USER")
  public class User extends UrlEntity{
  
      @Column(name="NAME", nullable = false)
      @NotEmpty(message="Name can not be empty")
      private String name;
  
      @Column(name="ROLE", nullable = false)
      @NotNull(message="Role can not be left blank")
      private Role role;
  
      @Column(name = "EMAIL_ADDRESS", nullable = false)
      @NotEmpty(message="email address can not be empty")
      private String emailAddress;
  
      public User(){}
  
      public String getName() {
          return name;
      }
      public void setName(String name) {
          this.name = name;
      }
      public Role getRole() {
          return role;
      }
      public void setRole(Role role) {
          this.role = role;
      }
  
      public String getEmailAddress() {
          return emailAddress;
      }
  
      public void setEmailAddress(String emailAddress) {
          this.emailAddress = emailAddress;
      }
  @Override
  public String toString() {
      return "\nUser [name=" + name + ", role=" + role + ", emailAddress="
              + emailAddress + "]";
  }
  </code></pre>
  
  <p>}</p>