我可以在 Struts2 验证器注释中使用日历吗?
是否可以在 Struts2 IntRangeFieldValidator 中使用 java.util.Calendar?
以下代码不会产生任何 OGNL 错误,但也不起作用。我正在尝试为年份范围创建验证规则,最小值 = 1970 年,最大值 = 当前日历年。
@RequiredFieldValidator(message="Year cannot be blank")
@IntRangeFieldValidator(message="Year must be greater than 1970", min="1970", max="java.util.Calendar.getInstance().get(java.util.Calendar.YEAR)", fieldName="year")
public Integer getYear() {
return year;
}
有没有更好的方法可以在不编写自定义验证器的情况下做到这一点? 任何/所有答复表示赞赏。提前致谢!
Is it possible to use the java.util.Calendar in a Struts2 IntRangeFieldValidator?
The following code does not produce any OGNL errors but does not work either. I'm trying to create a validation rule for a year range, min= 1970 and max= current calendar year.
@RequiredFieldValidator(message="Year cannot be blank")
@IntRangeFieldValidator(message="Year must be greater than 1970", min="1970", max="java.util.Calendar.getInstance().get(java.util.Calendar.YEAR)", fieldName="year")
public Integer getYear() {
return year;
}
Is there a better way to do this without writing a custom validator?
Any/All replies are appreciated. Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想应该是:
有待证实。
I think it should be:
To be confirmed.
您可以使用 DateRangeFieldValidator 吗?
http://struts .apache.org/2.0.11.2/struts2-core/apidocs/com/opensymphony/xwork2/validator/annotations/DateRangeFieldValidator.html
是其他验证器的列表:
以下 apache.org/2.0.11.2/struts2-core/apidocs/com/opensymphony/xwork2/validator/annotations/package-summary.html" rel="nofollow">http://struts.apache.org/2.0.11.2/ struts2-core/apidocs/com/opensymphony/xwork2/validator/annotations/package-summary.html
Are you able to use the DateRangeFieldValidator?
http://struts.apache.org/2.0.11.2/struts2-core/apidocs/com/opensymphony/xwork2/validator/annotations/DateRangeFieldValidator.html
Here's a list of additional validators:
http://struts.apache.org/2.0.11.2/struts2-core/apidocs/com/opensymphony/xwork2/validator/annotations/package-summary.html
尝试以这种方式使用@FieldExpressionValidator:
Try using @FieldExpressionValidator in such a manner: