You need to create a custom rule. If you look at the src for StrutsValidator
you can see how the included rules are written and it's pretty straightfwd
to create one of your own. You need to add a rule definition to the
validator-rules.xml or to your own rules file (and then you need to
reference that rules file in your struts-config.xml plug-in section where
you specifiy pathnames for ValidatorPlugIn).

This is a field-equality checking rule I used in a project I'm working on...
public static boolean validateEquals(Object bean, ValidatorAction va, Field
field, ActionErrors errors, HttpServletRequest request)
        {
                String value = ValidatorUtil.getValueAsString(bean,
field.getProperty());
            String fieldname = field.getVarValue("field");
            String value2 = ValidatorUtil.getValueAsString(bean, fieldname);

            boolean result = true;
            if (!GenericValidator.isBlankOrNull(value)) {
               try {
                 if (!value.equals(value2)) {
                    errors.add(field.getKey(),
StrutsValidatorUtil.getActionError(request, va, field));
                    result = false;
                  }
                } catch (Exception e) {
                    errors.add(field.getKey(),
StrutsValidatorUtil.getActionError(request, va, field));
                          result = false;
                  }
                }
            return result;
        }

-----Original Message-----
From: Rags Srinivasan [mailto:[EMAIL PROTECTED]]
Sent: Saturday, November 16, 2002 16:14
To: [EMAIL PROTECTED]
Subject: matching 2 input fields in Validator


Folks
sorry for asking this trivial question. How do i write a validation rule to
do consistency checks on 2 or more fields from the input form? say for
example
password and repeat-password.
Thanks
-vasan


--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to