1
public class Admin extends ActionSupport implements ModelDriven<AdminData>
  {
   AdminData adminData = new AdminData();
   public AdminData getModel()
     {
        return adminData;
    }


   @Validations(requiredStrings ={
      @RequiredStringValidator(type=ValidatorType.FIELD,fieldName="emailId"),
    @RequiredStringValidator(type=ValidatorType.FIELD,fieldName="password")}
    public String auth()
    {
     }


     @Validations(requiredStrings ={
     @RequiredStringValidator(type=ValidatorType.FIELD,fieldName="emailId"),
        @RequiredStringValidator(type=ValidatorType.FIELD,fieldName="firstName"),
        @RequiredStringValidator(type=ValidatorType.FIELD,fieldName="surName"),
        @RequiredStringValidator(type=ValidatorType.FIELD,fieldName="password")}
   public String create() throws DatabaseException
   {

    }

}

我的问题是,当我调用create()方法时,验证没有问题,但是当我调用auth()方法时,验证有问题,因为当我调用 auth 方法时,它用于验证名字和姓氏。

并且在 AdminData.java 中有所有的 getset

4

1 回答 1

0

默认情况下,Struts2 验证器将检查所有方法的所有验证约束。您可以将 struts 配置为仅查找与当前方法相关的验证约束。只需打开validateAnnotatedMethodOnly你的struts.xml

<struts>
    <package ...>
        <interceptors>
            <interceptor-stack name="defaultStack">

                .....

                <!-- Turning per method validation on -->
                <interceptor-ref name="validation">
                    <param name="validateAnnotatedMethodOnly">true</param>
                    <param name="excludeMethods">input,back,cancel,browse</param>
                </interceptor-ref>

                ......

            </interceptor-stack>
        </interceptors>
    </package>
</struts>

请参阅相应的文档条目:每种方法的不同验证

于 2013-04-05T13:16:49.093 回答