【发布时间】:2014-01-03 11:52:16
【问题描述】:
在这样的操作类中给定一个Boolean 字段。
@Namespace("/admin_side")
@ResultPath("/WEB-INF/content")
@ParentPackage(value="struts-default")
public final class TestAction extends ActionSupport implements Serializable, ValidationAware, ModelDriven<Entity>
{
private Boolean boolField;
public Boolean getBoolField()
{
return boolField;
}
public Boolean setBoolField(Boolean boolField)
{
this.boolField=boolField;
}
@Validations(requiredFields={@RequiredFieldValidator(fieldName="boolField", type= ValidatorType.FIELD, key="delete.row.confirm")})
@Action(value = "testAction",
results = {
@Result(name=ActionSupport.SUCCESS, type="redirectAction", location="Test.action"),
@Result(name = ActionSupport.INPUT, location = "Test.jsp")},
public String testAction()
{
return ActionSupport.SUCCESS;
}
// The rest of the action class.
}
动作类boolField 中的字段只有在设置为true 时才应该被验证。它可能是隐藏字段<s:hidden>,也可以通过查询字符串参数设置。
This 和 this 问题使用 XML 配置进行布尔字段验证,但不涉及注释。
如何使用注释验证此类布尔字段?
→我已经避免使用拦截器和其他东西来缩短代码。
【问题讨论】:
标签: java validation struts2 ognl struts2-convention-plugin