我正在制作注册表。
我需要检查两个密码字段是否相同。
<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;
}
}
我试过这个,但它给出了一个错误。对于资源类型,该方法getActionError(ServletContext, HttpServletRequest, ValidatorAction, Field)
未定义。