That's not a good solution.  I don't want to pollute my domain objects
with Struts 2 annotations, plus I didn't even know that Struts 2
validation annotations could be used anywhere other than on a Struts
Action. 

-----Original Message-----
From: Jim Kiley [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, July 01, 2008 11:43 AM
To: Struts Users Mailing List
Subject: Re: Validating objects in Collections

You can put the validation on Person's firstName() method.

On Tue, Jul 1, 2008 at 12:39 PM, Asleson, Ryan <[EMAIL PROTECTED]>
wrote:

>
> Hello,
>
> I'm using Struts 2.0.11.
>
> I have an HTML table.  Each row in the table represents a Person
object.
> Each column in the table has an input box for properties about the 
> person, such as firstName, lastName, etc.
>
> My Action has a Persons property that is a List<Person>.  Each input 
> box in the HTML table is indexed so as to populate the correct Person,

> for
> example:
>
> <input type="text" name="persons[0].firstName" value="Fred" />
>
> When the user posts the form, Struts 2 will populate the Person 
> objects appropriately.  So far so good.  However, I want to apply 
> validations to the input.  For example, firstName is required.  I want

> to use annotations for these validations as that is how I've done it
elsewhere.
>
> I added this annotation to the method in the Action:
>
> @Validations(
>    requiredStrings={
>        @RequiredStringValidator( type=ValidatorType.SIMPLE, fieldName 
> = "persons.firstName", message = "person.firstname.required" )
>    }
> )
>
> Hoping that the firstName property of each Person within List<Person> 
> would be checked to see if a value is provided.  However, it doesn't 
> seem to work; it always reports an error, even if all of the firstName

> input boxes are filled in.
>
> How can I validate the contents of objects within collections using 
> annotations?
>
> Thank you!!!
>
> -Ryan
>
>
>
>
>
> This e-mail message is being sent solely for use by the intended
> recipient(s) and may contain confidential information.  Any 
> unauthorized review, use, disclosure or distribution is prohibited.  
> If you are not the intended recipient, please contact the sender by 
> phone or reply by e-mail, delete the original message and destroy all
copies. Thank you.




--
Jim Kiley
Technical Consultant | Summa
[p] 412.258.3346 [m] 412.445.1729
http://www.summa-tech.com

This e-mail message is being sent solely for use by the intended recipient(s) 
and may contain confidential information.  Any unauthorized review, use, 
disclosure or distribution is prohibited.  If you are not the intended 
recipient, please contact the sender by phone or reply by e-mail, delete the 
original message and destroy all copies. Thank you.

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

Reply via email to