commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Power, David" <>
Subject Commons Validator String array Validation
Date Tue, 25 Mar 2008 20:59:31 GMT

I am using commons validator 1.3.1 and am using indexedProperty's for
String[] arrays.
I build up the list on the jsp dynamically so there could be one or more
entries with the same name.

Here is my struts config entry as part of a DynaValidatorForm

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

Then in my custom-forms.xml I have the following configuration rules

<field property="abc" indexedListProperty="abc"
	<arg key="aRI" resource="false" position="0"/>
	<arg name="intRange" key="${var:min}" resource="false"
	<arg name="intRange" key="${var:max}" resource="false"

This configuration works fine if there are 2 or more fields in the form
with the name 'abc', however when there is only one commons validator
sees it as a string and the following method throws a Validator

     * Returns the size of an indexed property from the object we're
     * @param bean The bean to extract the indexed values from.
     * @throws ValidatorException If there's an error looking up the
     * or, the property found is not indexed.
    private int getIndexedPropertySize(Object bean) throws
ValidatorException {
        Object indexedProperty = null;

        try {
            indexedProperty =

        } catch(IllegalAccessException e) {
            throw new ValidatorException(e.getMessage());
        } catch(InvocationTargetException e) {
            throw new ValidatorException(e.getMessage());
        } catch(NoSuchMethodException e) {
            throw new ValidatorException(e.getMessage());

        if (indexedProperty == null) {
            return 0;
        } else if (indexedProperty instanceof Collection) {
            return ((Collection)indexedProperty).size();
        } else if (indexedProperty.getClass().isArray()) {
            return ((Object[])indexedProperty).length;
        } else {
            throw new ValidatorException(this.getKey() + " is not

The method signature explains this as it says this will be thrown if it
is not an indexed property.

Is what I am trying to achieve possible with the current version of
commons validator? If so is there some configuration changes needed?

Thank you in advance

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message