struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brown, Melonie S. - Contractor" <Melonie.Br...@forscom.army.mil>
Subject RE: Custom Validator not being called
Date Tue, 27 May 2003 17:19:36 GMT
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. <SHANE.C.BAILEY@saic.com>
Reply-To: Struts Users Mailing List <struts-user@jakarta.apache.org>
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:Melonie.Brown@forscom.army.mil]

Sent: Tuesday, May 27, 2003 12:32 PM
To: 'struts-user@jakarta.apache.org'
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: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message