+-

有可能吗?
我做了一个自定义注释,检查2个字段是否等于 here.
我想验证字段“password”是否等于另一个字段“confirmedPassword”.现在,如果不是,我希望显示链接到confirmedPassword字段的错误消息.
我在jsp中使用< form:errors path =“”/>显示错误.还有另一种方法吗?
此注释电子邮件和已确认的电子邮件中还可能有另外两个字段.我怎么能区分哪个全局错误放在哪里……
我做了一个自定义注释,检查2个字段是否等于 here.
我想验证字段“password”是否等于另一个字段“confirmedPassword”.现在,如果不是,我希望显示链接到confirmedPassword字段的错误消息.
我在jsp中使用< form:errors path =“”/>显示错误.还有另一种方法吗?
此注释电子邮件和已确认的电子邮件中还可能有另外两个字段.我怎么能区分哪个全局错误放在哪里……
我希望这一切都有道理..
最佳答案
来自Hibernate Validator论坛的这个帖子似乎表明你想在自定义验证器的isValid()方法中添加类似下面代码的东西:
https://forum.hibernate.org/viewtopic.php?f=9&t=1003351&view=next
constraintValidatorContext.disableDefaultConstraintViolation();
constraintValidatorContext.buildConstraintViolationWithTemplate( errorMessage ).addNode("confirmPassword").addConstraintViolation();
.addNode(“confirmPassword”)位从文档中查找,它会自定义错误的路径:
http://download.oracle.com/javaee/6/api/javax/validation/ConstraintValidatorContext.html#buildConstraintViolationWithTemplate%28java.lang.String%29
然后,您应该能够通过在错误标记中使用path =“confirmPassword”来显示confirmPassword的错误.
点击查看更多相关文章
转载注明原文:将表单验证中生成的全局错误绑定到spring中的特定表单字段 - 乐贴网