java - Spring form validation using annotation and @Valid -


i having issues form validation.

controller:

@requestmapping(value = register_url, method = requestmethod.post)     public string registerpost(@valid registerform registerform,                                bindingresult result) {         if (result.haserrors()) {             return register_view;         }         system.out.println(registerform.getpassword());         return login_view;     } 

view:

<form:form action="register" commandname="registerform" method="post">             <table>                 <tr>                     <td>username:</td>                     <td><form:input path='username' /></td>                     <td><form:errors path="username"/></td>                 </tr>                 <tr>                     <td>password:</td>                     <td><form:password path='password'/></td>                     <td><form:errors path="password"/></td>                 </tr>                 <tr>                     <td>repeat password:</td>                     <td><form:password path='repeatedpassword'/></td>                     <td><form:errors path="repeatedpassword"/></td>                 </tr>                 <tr>                     <td colspan="2">&nbsp;</td>                 </tr>                 <tr>                     <td colspan='2'><input name="submit" type="submit">&nbsp;<input name="reset" type="reset"></td>                 </tr>             </table>         </form:form> 

form:

public class registerform {      @size(min = 3, max = 15)     private string username;      @size(min = 5)     private string password;      @size(min = 5)     private string repeatedpassword;     // getters , setters omitted } 

when enter empty values (username, password , repeatedpassword) no errors occurs (i have checked using debugger). looks no validation performed. binding values view ok (checked using debugger) ideas might wrong?

add following content context:

<mvc:annotation-driven /> <context:component-scan base-package="xxx.xxx.xxx" /> 

in guide, use "@springbootapplication" http://spring.io/guides/gs/validating-form-input/

the @springbootapplication annotation equivalent using @configuration, @enableautoconfiguration , @componentscan default attributes: http://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-using-springbootapplication-annotation.html


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -