开发者

problem with validating form in spring under hibernate validator

开发者 https://www.devze.com 2023-03-30 06:39 出处:网络
i have a problem with a simple form in spring that use validating with hibenate validator my form: <form:form method=\"POST\" commandName=\"info\">

i have a problem with a simple form in spring that use validating with hibenate validator my form:

 <form:form method="POST" commandName="info">

     username:<form:input path="username"/> <form:errors path="username"></form:errors>
     password:<form:password path="password"/><form:errors path="password"></form:errors> 
     <input type="submit" value="add new writer">
  </form:form>

my controller for form:

@RequestMapping(method=RequestMethod.POST,value={"/createnewuser"})
public String showCreateNewUserFrom( @javax.validation.Valid   Information info,Model model,BindingResult br)
{
    //System.out.println("hello post");
    if(br.hasErrors())
    {

        return "admin/createuserform";
    }
    else
    return "admin/createuserform";
}

my problem is when my form is invalide that throw exception!!i want jsp view of errors

org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 2 errors
Field error in object 'information' on field 'username': rejected value [vc]; codes [Size.information.username,Size.username,Size.java.lang.String,Size]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [information.username,username]; argumen开发者_Go百科ts []; default message [username],10,4]; default message [username must be at least 4 and at most 10 character]
Field error in object 'information' on field 'password': rejected value [fg]; codes [Size.information.password,Size.password,Size.java.lang.String,Size]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [information.password,password]; arguments []; default message [password],8,5]; default message [username must be at least 5 and at most 8 character]

i will be realy greatfull for anyhelp


From documentation:

The Errors or BindingResult parameters have to follow the model object that is being bound immediately as the method signature might have more that one model object and Spring will create a separate BindingResult instance for each of them [...] To get this working you have to reorder the parameters [...]

Looks like your case..

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号