Is your form subclassing either ValidatorForm (or DynaValidatorForm
depending on how you are defining your form)?

And not ValidatorActionForm (or DynaValidatorActionForm) since you
are basing your validation off of a form and not an action?

If these tests fail then I am out of suggestions :(

-----Original Message-----
From: Brown, Melonie S. - Contractor [mailto:[EMAIL PROTECTED]

Sent: Tuesday, May 27, 2003 1:20 PM
To: '[EMAIL PROTECTED]'
Subject: RE: Custom Validator not being called

I could live with that.  :)

The problem is that the custom validation isn't being called when the
required and minlength pass.

To test that, I changed the field settings to:

 <form name="changePasswordForm">
                   <field property="newPassword" depends="complexpassword">
                   </field>                        
                <field property="oldPassword" depends="required,minlength">
                        <arg0 key="changepassword.oldpassword" />
                        <arg1 name="minlength" key="${var:minlength}"
resource="false" />
                          <var>
                                 <var-name>minlength</var-name>
                                 <var-value>8</var-value>
                          </var>
                </field>
                 <field property="confirmnewPassword"
depends="required,minlength">
                        <arg0 key="changepassword.confirmpassword" />
                        <arg1 name="minlength" key="${var:minlength}"
resource="false"  />
                          <var>
                                 <var-name>minlength</var-name>
                                 <var-value>8</var-value>
                          </var>
                </field>
        </form>

-------- Original Message --------
Subject: RE: Custom Validator not being called
Date: Tue, 27 May 2003 12:31:04 -0400
From: Bailey, Shane C. <[EMAIL PROTECTED]>
Reply-To: Struts Users Mailing List <[EMAIL PROTECTED]>
Newsgroups: gmane.comp.jakarta.struts.user


Could it be that it is failing required or minlength
first and therefore isn't getting to your method?

-----Original Message-----
From: Brown, Melonie S. - Contractor [mailto:[EMAIL PROTECTED]

Sent: Tuesday, May 27, 2003 12:32 PM
To: '[EMAIL PROTECTED]'
Subject: Custom Validator not being called

I have the standard validation working just fine.  I have attempted to
branch out to use a custom validator for making sure that passwords follow a
certain set of rules.  The custom validation method does not get called.   I
set the logging to debug, but the output only confirmed that my method isn't
being called.  Suggestions for how to debug further would be greatly
appreciated.

[log when standard validations fail]
DEBUG Date = 2003-05-27 12:22:54,543 [Thread-5]
org.apache.struts.action.RequestProcessor Line = 942 -  Validation failed,
returning to '/gotochangepassword.do'

[log when standard validations pass - should call my validator]
DEBUG Date = 2003-05-27 12:19:14,939 [Thread-4]
org.apache.struts.action.RequestProcessor Line = 915 -   No errors detected,
accepting input
 

Following are the relevant snippets of code:

Validator-rules.xml
--------------------------
        
        <validator name="complexpassword"
     classname="foo.SecurePasswordValidator"
     method="validateComplexPassword"
     methodparams="java.lang.Object,
                   org.apache.commons.validator.ValidatorAction,
                   org.apache.commons.validator.Field,
                   org.apache.struts.action.ActionErrors,
                   javax.servlet.http.HttpServletRequest" 
     msg="errors.changepasswordnotfollowrules">
     </validator>


Validation.xml
-----------------
<form name="changePasswordForm">
                   <field property="newPassword"
depends="required,minlength,complexpassword">
                          <arg0 key="changepassword.newpassword" />
                          <arg1 name="minlength" key="${var:minlength}"
resource="false"  />
                          <var>
                                 <var-name>minlength</var-name>
                                 <var-value>8</var-value>
                          </var>                          
                   </field>                        
                <field property="oldPassword" depends="required,minlength">
                        <arg0 key="changepassword.oldpassword" />
                        <arg1 name="minlength" key="${var:minlength}"
resource="false" />
                          <var>
                                 <var-name>minlength</var-name>
                                 <var-value>8</var-value>
                          </var>
                </field>
                 <field property="confirmnewPassword"
depends="required,minlength">
                        <arg0 key="changepassword.confirmpassword" />
                        <arg1 name="minlength" key="${var:minlength}"
resource="false"  />
                          <var>
                                 <var-name>minlength</var-name>
                                 <var-value>8</var-value>
                          </var>
                </field>
        </form>



Validation method
--------------------

public static boolean validateComplexPassword(
        Object bean,
        ValidatorAction va,
        Field field,
        ActionErrors errors,
        HttpServletRequest request)
    {
        String value = null;
        if (isString(bean))
        {
            value = (String)bean;
        }
        else
        {
            value = ValidatorUtil.getValueAsString(bean,
field.getProperty());
        }
        boolean upperCase = false;
        boolean lowerCase = false;
        boolean digit = false;        
        for (int i = 0; i < value.length(); i++)
        {
            if (Character.isLowerCase(value.charAt(i)))
            {
                lowerCase = true;
            }
            if (Character.isDigit(value.charAt(i)))
            {
                digit = true;
            }
            if (Character.isUpperCase(value.charAt(i)))
            {
                upperCase = true;
            }            
        }
        // verify that the new password has the requisite combination of
elements (1, A, a)
        if (!(upperCase && lowerCase && digit))
        {
            errors.add(
                field.getKey(),
                Resources.getActionError(request, va, field));
            return false;
        }
        return true;
    }

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

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

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

Reply via email to