Spring MVC 表单验证错误消息
我有以下形式:
<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>
然后我有验证器,它验证值并发送错误。
我想做的是添加额外的错误标签,例如
<form:errors path="generarError" />
在我的验证器中我可以执行以下操作:
if (user.getA().equals(user.getB()))
errors.rejectValue("generarError",
"lengthOfUser.user.generarError",
"A is not equeal to B. Sorry");
}
重要的是我的 GeneralError 不是用户对象的成员。
我怎样才能做到这一点?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜你不能将错误绑定到不存在的字段。
但是,如果您想要显示属于整个表单而不是其中某个字段的错误,您可以执行以下操作:
。
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:
.