I have the following form:
<form:form method="POST" action="signin.dlp" commandName="user" >
<form:input path="useremail" id="useremail" /><FONT color="red"><form:errors path="useremail" /></FONT><Br />
<form:password path="pswd" id="pswd" /><FONT color="red"><form:errors path="pswd" /></FONT> <br />
<input id ="login" type="submit" value="Login"></input>
</form:form>
and then I i have Validator which validates value from and send error.
what I would like to do is to add extra error 开发者_如何学编程label, for example
<form:errors path="generarError" />
and inside my validator I can do the following:
if (user.getA().equals(user.getB()))
errors.rejectValue("generarError",
"lengthOfUser.user.generarError",
"A is not equeal to B. Sorry");
}
The important thing that I generalError is not member of user object.
How can I do that?
I guess you cannot bind an error to the nonexistent field.
However, if you want to show an error that belongs to the form as a whole rather then to one of its fields, you can do the following:
<form:errors />
.
errors.reject("lengthOfUser.user.generarError", "A is not equeal to B. Sorry");
精彩评论