Hi,Ben.

I think "required"(and others also) is work only String,
not array.
I was same situation, so I made a class that...

************************
public class InputChecks extends FieldChecks {
    public static boolean validateRequiredArray(Object
bean,
                                           ValidatorAction
va, Field field,
                                           ActionErrors
errors,
                                          
HttpServletRequest request) {

        String[] values = (String[])bean;
        
        for (int i=0;i<values.length;i++) {
        
if(!FieldChecks.validateRequired(values[i],va,field,errors,request)){
          return false;
         }
        }
        return true;       
    }
}
************************

and add [validator-rules.xml] 

************************
      <validator name="requiredArray"
            classname="zz.yy.xx.InputChecks"
               method="validateRequiredArray"
         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.required">
      </validator>

************************

This work all item in array.
But, I don't know that is best way...

----- Original Message ----- 
From: "Ben Anderson" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, June 19, 2003 9:17 PM
Subject: validate String[]


> I have a page with multiple checkboxes (I'm using
<html:multibox>) and I 
> need to validate that at least one of them is checked.
> 
> <code file="struts-config.xml">
>        <form-bean
>            name="reportForm"
>           
type="org.apache.struts.validator.DynaValidatorActionForm">
>            <form-property name="reportList"
type="java.lang.String[]"/>
> </code>
> 
> <code file="validation.xml">
>        <field property="reportList" depends="required">
>                <msg name="required"
key="err.reportList.required"/>
> </code>
> 
> This doesn't seem to work.  I've been reading through
Struts Chapter 12 pdf 
> about validation, but can't seem to find any cases where
the property is an 
> array of Strings.  Any thoughts?
> Thanks in advance,
> Ben Anderson
> 
>
_________________________________________________________________
> STOP MORE SPAM with the new MSN 8 and get 2 months FREE*
 
> http://join.msn.com/?page=features/junkmail
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
[EMAIL PROTECTED]
> For additional commands, e-mail:
[EMAIL PROTECTED]
> 

__________________________________________________
Do You Yahoo!?
Yahoo! BB is Broadband by Yahoo!  http://bb.yahoo.co.jp/


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

Reply via email to