java - @Vaild is not working -


i want check size validation studenthobby object , using @size annotation , using @valid annotation.

i providing less value defined in @size annotation still getting result instead of error.

i tried things didn't come solutions.

studentadmissioncontroller.java

package com.diwakar;  import javax.validation.valid;  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.requestmapping; import org.springframework.web.bind.annotation.requestmethod; import org.springframework.web.servlet.modelandview;   @controller public class studentadmissioncontroller {      @initbinder     public void initbinder(webdatabinder binder) {         //binder.setdisallowedfields(new string[] {"studentmobile"});         //simpledateformat date = new simpledateformat("dd**mm**yyyy");         //binder.registercustomeditor(date.class, "studentdob", new customdateeditor(date, false));          binder.registercustomeditor(string.class, "studentname", new studentnameeditor());     }      @requestmapping(value="/admission.html", method = requestmethod.get)     public modelandview getadmissionform() {          modelandview model =  new modelandview("admissionform");         //model.addobject("headermessage", "diwakar college of engineering.!!");         return model;     }      @requestmapping(value="/submitform", method =  requestmethod.post)     public modelandview submitadmissionform(@valid @modelattribute("st1") student st1, bindingresult result) {          if (result.haserrors()) {             modelandview model =  new modelandview("admissionform");             return model;         }          modelandview model = new modelandview("admissionsuccess");         //model.addobject("headermessage", "diwakar college of engineering.!!");         return model;     }         @modelattribute     public void addcommonmessage(model model) {         model.addattribute("headermessage", "diwakar college of engineering.!!");     } 

student.java

package com.diwakar;  import java.util.arraylist; import java.util.date;  import javax.validation.constraints.size;  public class student {      private string studentname;      @size(min=3, max=10)     private string studenthobby;      private long studentmobile;      private date studentdob;     private arraylist<string> studentskills;     private address studentaddress;      public string getstudentname() {         return studentname;     }     public void setstudentname(string studentname) {         this.studentname = studentname;     }     public string getstudenthobby() {         return studenthobby;     }     public void setstudenthobby(string studenthobby) {         this.studenthobby = studenthobby;     }     public long getstudentmobile() {         return studentmobile;     }     public void setstudentmobile(long studentmobile) {         this.studentmobile = studentmobile;     }     public date getstudentdob() {         return studentdob;     }     public void setstudentdob(date studentdob) {         this.studentdob = studentdob;     }     public arraylist<string> getstudentskills() {         return studentskills;     }     public void setstudentskills(arraylist<string> studentskills) {         this.studentskills = studentskills;     }     public address getstudentaddress() {         return studentaddress;     }     public void setstudentaddress(address studentaddress) {         this.studentaddress = studentaddress;     }    } 

spring-dispatcher-servlet.xml

<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans"     xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xmlns:mvc="http://www.springframework.org/schema/mvc"     xmlns:p="http://www.springframework.org/schema/p"     xmlns:context="http://www.springframework.org/schema/context"     xsi:schemalocation="http://www.springframework.org/schema/beans                         http://www.springframework.org/schema/beans/spring-beans.xsd                         http://www.springframework.org/schema/context                         http://www.springframework.org/schema/context/spring-context.xsd                         http://www.springframework.org/schema/mvc                         http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">    <!--      <bean id="handlermapping" class="org.springframework.web.servlet.handler.beannameurlhandlermapping" />           <bean name="/welcome.html" class="com.diwakar.hellocontroller" />  -->       <context:component-scan base-package="com.diwakar" />      <mvc:annotation-driven />       <bean id="viewresolver" class="org.springframework.web.servlet.view.internalresourceviewresolver">         <property name="prefix" value="/web-inf/" />         <property name="suffix" value=".jsp"></property>      </bean>                  </beans> 

here admission page though providing 1 one character giving me submit form instead of error. admission.html page

this submit form getting after submitting value 1 character. submitform


Comments