You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Bailey, Shane C." <SH...@saic.com> on 2003/08/04 18:35:09 UTC

Using the wrong version of valiator?

 

Validation is working for my String[] dynaform attributes.  I have seen
others on the list say it works for them.

So I looked at the source code (of my commons-validator.jar using jad).
Either it can't be working or I am using

the wrong version of that jar.   Do I need to get the latest
commons-validator.jar?  If so, I don't remember where I

retrieved the one I have now.  Did it come with Struts download?

 

Source Code:

    public static boolean validateRequired(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());

        }

        if (GenericValidator.isBlankOrNull(value)) {

            errors.add(field.getKey(),

                                 Resources.getActionError(request, va,
field));

 

            return false;

        } else {

            return true;

        }

 

    }

 

 

Problem:

ValidatorUtil.getValueAsString(bean, field.getProperty()) does a toString()
on the value and a toString() on a String[] 

which isn't null is some String like "[Ljava.lang.String;@3cfaab"   and so
then isBlankOrNull() is checking for null or

value.trim().length==0

 

Here is how my field is declared on the JSP:

           <html:select property="roles" multiple="true" size="7">

                                                <html:options 

 
collection="<%=acint21.web.util.Const.ROLE_TYPES%>" 

 
property="roleName" />

                                                </html:select>

 

Here is how it is declared in the struts config:

            <form-property name="roles" type="java.lang.String[]"/>