Thanks for the explanation Matt,

I sure wasn't expecting the validator to be looking for a 'quantity'
property on the elements of the array.
Seems totally inconsistent to me.

I expected to be able to signify the validation field as an array of
elements or indexed etc and have the validator iterate over the elements and
validate each one. ie specify property='quantityArray' indexed='true' or
similar. Or possibly even have the validator introspect the value and
determine that it is an array that needs to be processed, though I favour
the former.

William


----- Original Message ----- 
From: "Matt Bathje" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <user@struts.apache.org>
Sent: Friday, January 07, 2005 1:03 AM
Subject: Re: [validator] indexed properties


> William -
>
> The problem here is that validator is expecting quantityArray to contain
> a property called quantity for each element it contains. (For example:
> quantityArray[0].quantity, quantityArray[1].quantity etc.) Since
> quantityArray is an array of Integer, it obviously does not contain a
> property called quantity.
>
> Overall though, the problem is that an Integer (and any of the other
> java type-wrapper classes) does not contain getters and setters for
> their value properties, and therefore cannot be used in an array and
> with the built in validator.
>
> I think you have 2 choices here, the first being to use the validate
> method inside your ActionForm. The second option would be to setup a new
> class with a quantity property and getters/setters for that property,
> then make quantityArray an array of that type.
>
> Matt
>
>
>
> William Ferguson wrote:
> > Hi all,
> >
> > even after scanning the doco, examples, source code and previous posts I
> > still can't get validation to happen for an indexed field in my Struts
> > (1.2.4) application working. I would really appreciate some help
crafting
> > the appropriate validation definition.
> >
> >
> > My form is defined as
> > <form name="/cart/updateItems">
> >   <field property="quantity" indexedListProperty="quantityArray"
> > depends="required, integer">
> >   </field>
> > </form>
> >
> > A 'quantityArray' parameter is supplied with the Request and is an array
of
> > Integer like Strings.
> >
> > The Struts ActionForm has the following methods:
> >   public Integer getQuantity(int index);
> >
> >   /*
> >    * NB it is not expected that this method will ever be called,
> >    * but I think it is needed so that the commons-validator recognises
> > 'quantity' as a property.
> >    */
> >   public void setQuantity(int index, Integer quantity);
> >   public Integer[] getQuantityArray();
> >   public void setQuantityArray(Integer[] quantity);
> >
> > But this combination causes the following Exception to be thrown during
> > validation:
> > 24734  ERROR org.apache.commons.validator.util.ValidatorUtils - Unknown
> > property 'quantity'
> > java.lang.NoSuchMethodException: Unknown property 'quantity'
> >         at
> >
org.apache.commons.beanutils.PropertyUtils.getSimpleProperty(PropertyUtils.j
> > ava:1175)
> >         at
> >
org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUtils.j
> > ava:772)
> >         at
> >
org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:80
> > 1)
> >         at
> >
org.apache.commons.validator.util.ValidatorUtils.getValueAsString(ValidatorU
> > tils.java:105)
> >         at
> >
org.apache.struts.validator.FieldChecks.validateRequired(FieldChecks.java:87
> > )
> >         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >         at
> >
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
> > )
> >         at
> >
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
> > .java:25)
> >         at java.lang.reflect.Method.invoke(Method.java:324)
> >         at
> >
org.apache.commons.validator.ValidatorAction.executeValidationMethod(Validat
> > orAction.java:567)
> >         at
> > org.apache.commons.validator.Field.validateForRule(Field.java:811)
> >         at org.apache.commons.validator.Field.validate(Field.java:890)
> >         at org.apache.commons.validator.Form.validate(Form.java:174)
> >         at
> > org.apache.commons.validator.Validator.validate(Validator.java:367)
> >         at
> >
org.apache.struts.validator.ValidatorForm.validate(ValidatorForm.java:112)
> >
> > I tried dozens of different combos with no luck.
> > What do I need to do to validate a collection of properties of unknown
size
> > using the commons-validator?
> >
> > NB crossposting to both commons and struts lists.
> >
> > William
> >
> >
> > ---------------------------------------------------------------------
> > 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]
>
>
>
> -- 
> No virus found in this incoming message.
> Checked by AVG Anti-Virus.
> Version: 7.0.300 / Virus Database: 265.6.8 - Release Date: 03-Jan-05
>
>


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

Reply via email to