struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jim Kiley" <jhki...@summa-tech.com>
Subject Re: Validating objects in Collections
Date Tue, 01 Jul 2008 16:43:01 GMT
You can put the validation on Person's firstName() method.

On Tue, Jul 1, 2008 at 12:39 PM, Asleson, Ryan <asleson@biworldwide.com>
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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message