0

登録用紙を作っています。

両方のパスワード フィールドが同じかどうかを確認する必要があります。

<validator name="twofields"
           classname="com.mysite.StrutsValidator"
           method="validateTwoFields"
           msg="errors.twofields"/>

<field property="password"
       depends="required,twofields">

    <arg position="0" key="typeForm.password.displayname"/>
    <var>
       <var-name>secondProperty</var-name>
       <var-value>password2</var-value>
    </var>
</field>

方法

public class StrutsValidator {

    public static boolean validateTwoFields(
            Object bean,
            ValidatorAction va,
            Field field,
            ActionErrors errors,
            HttpServletRequest request,
            ServletContext application) {

        String value = ValidatorUtils.getValueAsString(
            bean,
            field.getProperty());
        String sProperty2 = field.getVarValue("secondProperty");
        String value2 = ValidatorUtils.getValueAsString(
            bean,
            sProperty2);

        if (!GenericValidator.isBlankOrNull(value)) {
            try {
                if (!value.equals(value2)) {
                    errors.add(field.getKey(),
                               Resources.getActionError(
                                   application,
                                   request,
                                   va,
                                   field));

                    return false;
                }
            }
            catch (Exception e) {
                errors.add(field.getKey(),
                           Resources.getActionError(   //This line is giving an error.
                               application,
                               request,
                               va,
                               field));
                return false;
            }
        }
        return true;
    }
}

私はこれを試しましたが、エラーが発生しています。タイプ ResourcesのメソッドgetActionError(ServletContext, HttpServletRequest, ValidatorAction, Field)は定義されていません。

4

1 に答える 1

0

あなたの正確なStrutsバージョンは何ですか? 少なくともStruts 1.1 API ドキュメントによると、Resources.getActionErrorメソッドのシグネチャは次のとおりです。

getActionError( 
    javax.servlet.http.HttpServletRequest request,   
    org.apache.commons.validator.ValidatorAction va,
    org.apache.commons.validator.Field field
)

これは、メソッド呼び出しからアプリケーション パラメーターを削除する必要があることを示しています。

errors.add(
    field.getKey(),
    Resources.getActionError(
        request,
        va,
        field));
于 2011-04-19T05:32:17.940 に答える