You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ryan Cornia <RC...@utah.gov> on 2002/12/09 19:30:50 UTC

Pluggable Validation Not Being called, any ideas?

I'm using Struts 1.1B2, and have tried to create a pluggable validator
similar to the example on Davids site.

In my validation-rules.xml I have -
 <validator name="twofields"
       classname="us.ut.state.dced.filmrg.StrutsValidator"
       method="validateTwoFieldsEqual"
       msg="errors.twofieldsequal"/>

Then in my validation.xml, I have -

<field property="password" depends="required,twofields">
   <arg0 key="candidateForm.password.displayname"/>
   <var>
           <var-name>secondProperty</var-name>
            <var-value>confirmPassword</var-value>
    </var>
</field>

When I run the application, the validation function is never called! (I
put system.out.println in it, and they are not executed.) The function
is -
   public static boolean validateTwoFieldsEqual(java.lang.Object bean,
                                  
org.apache.commons.validator.ValidatorAction va,
                                   org.apache.commons.validator.Field
field,
                                   ActionErrors errors,
                                  
javax.servlet.http.HttpServletRequest request)
    {   
        System.out.println("In Here!");
        String value = ValidatorUtil.getValueAsString(bean,
field.getProperty());
        String sProperty2 = field.getVarValue("secondProperty");
        String value2 = ValidatorUtil.getValueAsString(bean,
sProperty2);
        
        if (!GenericValidator.isBlankOrNull(value)) {
            try {
                if (!value.equals(value2)) {
                    errors.add(field.getKey(),
StrutsValidatorUtil.getActionError(request, va,  field));
                    
                    return false;
                }
            } catch (Exception e) {
                errors.add(field.getKey(),
StrutsValidatorUtil.getActionError(request, va, field));
                return false;
            }
        }
        
        return true;
    }

Any ideas how to get the validation function called? Do I need to
"register" it somewhere to get it to work?

Thanks,
Ryan


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>