Spring 3 Form Validation is working for @NotNull but not working for @Size annotation -
i facing problem spring form validation. works @notnull annotation how not working @size. attaching code below. in advance.
package com.doctor; import javax.validation.constraints.notnull; import javax.validation.constraints.size; public class doctor { @notnull(message="cannot null") private string uname; @size(min=1,max=8,message="min 1 , 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; } .................... ...................
doctorcontroller
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"; } } }
display page
<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form"%> <h2>create doctor account</h2> <sf:form method="post" modelattribute="doctor" enctype="multipart/form-data"> <fieldset> <table> <tr> <td><sf:label path="uname">user name:</sf:label></td> <td><sf:input path="uname" /><br /> <sf:errors path="uname" /> </td> </tr> <tr> <td><sf:label path="password">password:</sf:label></td> <td><sf:password path="password" showpassword="true" /> <br /> <sf:errors path="password" /></td> </tr> <tr> <td><sf:label path="doctor_fname">first name:</sf:label></td> <td><sf:input path="doctor_fname" size="15" /><br /> </td> </tr> <tr> <td><sf:label path="doctor_lname">last name:</sf:label></td> <td><sf:input path="doctor_lname" size="15" /><br /></td> </tr> <tr> <td><sf:label path="address">address:</sf:label></td> <td><sf:input path="address" size="15" /><br /></td> </tr> <tr> <td><sf:label path="dept_id">department:</sf:label></td> <td><sf:input path="dept_id" size="15" /><br /></td> </tr> <tr> <td><sf:label path="experience">experience:</sf:label></td> <td><sf:input path="experience" size="15" /><br /></td> </tr> <tr> <td><sf:label path="email">email address:</sf:label></td> <td><sf:input path="email" size="30" /> <small>in case forget something</small><br /> </td> </tr> <tr> <td><sf:label path="phone">phone:</sf:label></td> <td><sf:input path="phone" size="30" /> <small>in case forget something</small><br /> </td> </tr> <tr> <td><label for="resume">resume:</label></td> <td><input name="resume" type="file" /> </tr> <tr> <td><label for="image">profile image:</label></td> <td><input name="image" type="file" /> </tr> <tr> <th></th> <td><input name="commit" type="submit"> </tr> </table> </fieldset> </sf:form>
i don't understand why @size password not working.
help highly appreciated.
the issue seems using multipart form dont think see mention multipartresolver. if needed here how can add it
<bean id="multipartresolver class="org.springframework.web.multipart.commons.commonsmultipartresolver">
Comments
Post a Comment