title: Spring MVC validations Not working
body: <p>I am a newbie in spring validations.I have a <strong>loginform.html</strong> with 4 text fields and i was trying to validate them but the <em>validations are not working</em> in my form.
  But it accepts each and every value i entered.</p>
  
  <p><em>For example : If i enter an improper email it should throw me an validation error like "Enter proper Email ID</em>" </p>
  
  <p><strong><em>loginform.java</em></strong></p>
  
  <pre class="lang-java prettyprint-override"><code>public class loginform {
      @NotEmpty
      private String user;
  
      @NotEmpty
      @Email
      private String email;        
  
      @NotEmpty(message = "Phone should not be blank.")
      @Size(min = 10,max = 10)
      private String phone;
  
      @NotEmpty(message = "Enter your blog URL")
      @URL
      private String blog;
      // Get and set methods}
  </code></pre>
  
  <p><strong><em>login.html</em></strong></p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;form:form action="login.html" commandName="userDetails"&gt;
  &lt;table&gt;
  &lt;tr&gt;
      &lt;td&gt;&lt;font face="verdana" size="2px"&gt;User&lt;/font&gt;&lt;/td&gt;
      &lt;td&gt;:&lt;/td&gt;
      &lt;td&gt;
      &lt;font face="verdana" size="2"&gt;
      &lt;form:input path="user" /&gt; &lt;form:errors path="user"&gt;&lt;/form:errors&gt;
      &lt;/font&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
      &lt;td&gt;&lt;font face="verdana" size="2px"&gt;Email&lt;/font&gt;&lt;/td&gt;
      &lt;td&gt;:&lt;/td&gt;
      &lt;td&gt;
      &lt;font face="verdana" size="2"&gt;
      &lt;form:input path="email" /&gt; &lt;form:errors path="email"&gt;&lt;/form:errors&gt;
      &lt;/font&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
      &lt;td&gt;&lt;font face="verdana" size="2px"&gt;Phone&lt;/font&gt;&lt;/td&gt;
      &lt;td&gt;:&lt;/td&gt;
      &lt;td&gt;
      &lt;font face="verdana" size="2"&gt;
      &lt;form:input path="phone" /&gt; &lt;form:errors path="phone"&gt;&lt;/form:errors&gt;
      &lt;/font&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
      &lt;td&gt;&lt;font face="verdana" size="2px"&gt;Blog&lt;/font&gt;&lt;/td&gt;
      &lt;td&gt;:&lt;/td&gt;
      &lt;td&gt;
      &lt;font face="verdana" size="2"&gt;
      &lt;form:input path="blog" /&gt; &lt;form:errors path="blog"&gt;&lt;/form:errors&gt;
      &lt;/font&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
      &lt;td&gt;
      &lt;input type="submit" value="Submit" /&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form:form&gt;
  </code></pre>
  
  <p><strong><em>ContactController.java</em></strong></p>
  
  <pre class="lang-java prettyprint-override"><code>@Controller
  public class ContactController {
  
  @RequestMapping(value = "/get", method = RequestMethod.GET)
  public String get(ModelMap model) {
      loginform ud = new loginform();
       ud.setUser("prem");
       ud.setEmail("@gmail.com");
      model.addAttribute("userDetails",ud);
      return "login"; 
  }
  
  @RequestMapping("/login")
  public String loginCheck(@Valid loginform userDetails, BindingResult result, ModelMap model) {
  
      if (result.hasErrors()) {
          return "login";
      } else {
          model.addAttribute("lfobj", userDetails);
          return "success";
      }
  }
  </code></pre>
  
  <p><strong><em>spring-servlet.xml</em></strong></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;context:annotation-config /&gt;
  &lt;context:component-scan base-package="net.viralpatel.spring3.controller" /&gt; 
  
  &lt;bean id="jspViewResolver"
      class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;property name="viewClass"
          value="org.springframework.web.servlet.view.JstlView" /&gt;
      &lt;property name="prefix" value="/WEB-INF/jsp/" /&gt;
      &lt;property name="suffix" value=".jsp" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"&gt;
     &lt;property name="basename" value="props" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p><strong><em>success.html</em></strong></p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;body&gt;
  &lt;font face="verdana" size="2"&gt;Welcome Mr. &lt;b&gt;${lfobj.user}&lt;/b&gt;,&lt;br&gt;
  Validations Success..!&lt;br&gt;&lt;br&gt;
  &lt;u&gt;You Entered&lt;/u&gt;&lt;br&gt;
  &lt;/font&gt;
  
  &lt;table&gt;
      &lt;tr&gt;&lt;td&gt;Email&lt;/td&gt;&lt;td&gt;${lfobj.email}&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;Phone&lt;/td&gt;&lt;td&gt;${lfobj.phone}&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;Website&lt;/td&gt;&lt;td&gt;${lfobj.blog}&lt;/td&gt;&lt;/tr&gt;
  &lt;/table&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p><strong><em>props.properties</em></strong></p>
  
  <pre><code>NotEmpty.userDetails.user = User Name is required
  NotEmpty.userDetails.email = Email is required
  
  Email.userDetails.email = Enter valid email Id
  URL.userDetails.email = Enter valid URL
  </code></pre>
  
  <p><strong>OUTPUT</strong> : While running :(loginform.html - getting inputs)</p>
  
  <pre><code>*User :  sriprem 
  Email :  sri 
  Phone :  1323sri 
  Blog :   nice*
  </code></pre>
  
  <p><strong>It has show me the eror from my "props.properties" file but it doesnt show just directly gets all my input !!</strong> </p>
  
  <pre><code>Success.html
  
  Welcome Mr. sriprem,
  Validations Success..!
  
  You Entered
  Email   prem 
  Phone   1234sri 
  Website nice 
  </code></pre>
  
  <p>In above scenario everything was in wrong format yet it accepts the data ! Can anyone tell me what was wrong in my validations.  </p>