[英]Spring Validation Annotations Order
I want to ask is it possible to set explicitly the validation order in Spring. 我想问一下是否可以在Spring中明确设置验证顺序。 I mean, I have this command object:
我的意思是,我有这个命令对象:
public class UserData {
@NotBlank
private String newPassword;
@NotBlank
private String confirmPassword;
@Email(applyIf="email is not blank")
@NotBlank
private String email;
@NotBlank
private String firstName = "";
private String middleName = "";
@NotBlank
private String lastName = "";
// getters/setters
}
and I display my error messages on top of the page like this: 我在页面顶部显示我的错误消息,如下所示:
<spring:hasBindErrors name="${userData}">
<ul class="errors">
<c:forEach items="${errors.allErrors}" var="error">
<li><spring:message message="${error}"/></li>
</c:forEach>
</ul>
</spring:hasBindErrors>
The problem is no matter what my error messages are displayed in the following order: 问题是我的错误消息按以下顺序显示:
* Fill you last name. * Fill you password. * Fill your emailaddress. * Fill you password again. * Select your gender. * Fill your first name.
It is not random, because this order is preserved every time. 它不是随机的,因为每次都会保留此顺序。 It is not alphabetical, or any other order... I am really stuck.
这不是按字母顺序或任何其他顺序...我真的被卡住了。 Can someone help please?
有人可以帮忙吗?
SpringModules is a dead project, it's no longer supported. SpringModules是一个死的项目,它不再受支持。 If you need JSR-303 validation support in Spring, I suggest using the reference implementation, Hibernate Validator , and wire it up like so .
如果你需要在Spring中使用JSR-303验证支持,我建议使用参考实现, Hibernate Validator ,并将其连接起来 。
Having said that, this may not fix your problem, but at least you'll be using up-to-date libraries, likely making it easier to fix. 话虽如此,这可能无法解决您的问题,但至少您将使用最新的库,可能更容易修复。
I've found that using @GroupSequence works, though it doesn't feel like a proper solution. 我发现使用@GroupSequence工作,虽然它不是一个合适的解决方案。
See http://www.jroller.com/eyallupu/entry/jsr_303_beans_validation_using for a quick tutorial. 有关快速教程,请参阅http://www.jroller.com/eyallupu/entry/jsr_303_beans_validation_using 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.