struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Asleson, Ryan" <asle...@BIWORLDWIDE.com>
Subject Validating objects in Collections
Date Tue, 01 Jul 2008 16:39:11 GMT
 
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.
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message