Okay let me rephrase this.  Here is the "required" validator rules for Struts 
1.2 from the validator-rules.xml file: 

<validator name="required"
            classname="org.apache.struts.validator.FieldChecks"
               method="validateRequired"
         methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionMessages,
                       org.apache.commons.validator.Validator,
                       javax.servlet.http.HttpServletRequest"
                  msg="errors.required"/>

Does some know how to create a new rules using these methodParams?  Is there an 
example out there somewhere?

--Brad Simonin


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Tue 10/25/2005 3:35 PM
To: user@struts.apache.org
Subject: Question on creating new Validation Rules in Struts 1.2
 
Hello there.

Are there examples for creating a new Validation Rule using a new class for 
validating and then updating the validator-rules.xml file? I found a few 
examples but they are for Struts 1.1.   Below is a test class I am creating and 
then a copied version of a rule added to the validator-rules.xml from Struts 
1.2.  As you can see from what I have provided the method arguments are 
different for the validator-rules.xml of Struts 1.2.  Any clue would be 
appreciated.  

--Brad Simonin 

My class is as follows:

package edu.nmsu.psl.validators;

import javax.servlet.http.HttpServletRequest;
import org.apache.commons.validator.Field;
import org.apache.commons.validator.ValidatorAction;
import org.apache.commons.validator.ValidatorUtil;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.validator.Resources;

public class ActiveDirectoryValidator {
        
        public static boolean validateActiveDirectoryName(Object bean,
                        ValidatorAction action,
                        Field field,
                        ActionErrors errors,
                        HttpServletRequest request) {
                
                String value = ValidatorUtil.getValueAsString(bean, 
field.getProperty());
                
                if (value == null) value = "";
                
                if (!value.equals("Brad")) {
                                errors.add(field.getKey(), 
Resources.getActionError(request, action, field));
                                return false;
                } else {
                                return true;
                }
                
        }

}


My validator-rules.xml is as follows:

<validator name="activeDirectory"
            classname="edu.nmsu.psl.validators.ActiveDirectoryValidator"
               method="validateActiveDirectoryName"
         methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionMessages,
                       org.apache.commons.validator.Validator,
                       javax.servlet.http.HttpServletRequest"
                  msg="errors.activeDirectory"/>




---------------------------------------------------------------------
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