I don't know if this helps, but when I validate a list or array , i use
OGNL's selection/projection facility :
i.e. :
customers.{ ? #this.age gt 0 and #this.username neq null }.size() eq
customers.size
creates a list of all customers whose age is greater than zero and who have
a username and checks that it is the same as the incoming array ( i.e.
everyone has a username and an age )
For the second part,
in your Object's -conversion.xml file
declare the type information of the element, like so :
Element_customers = my.Customer
more info here :
http://struts.apache.org/2.x/docs/type-conversion.html
Alex Wibowo wrote:
>
> Hi all...
>
> I am using Struts 2.0. Has anyone ever done validation on individual item
> in
> java.util.List before?
>
> Say, I have a property
> List<Customer> customers
> in my Action, and Customer is defined as:
>
> public class Customer{
> private String username; // must not be empty
> private int age; // must be > 0
> }
>
> In the JSP I have the following:
>
>
> <c:forEach begin="0" end="10" var="i">
> <s:textfield key="customers[${i}].username" />
> <s:textfield key="customers[${i}].age" />
> </c:forEach>
>
>
> How can I enforce using struts validation (preferrably through annotation)
> so that:
> - both username and age are compulsory
> - age must be an integer
>
>
> Secondly, since "age" is of type "int".. when user enter characters
> (numbers) in the textfield, they get converted to 0 (somehow).
> How can I prevent this?
>
>
>
> Thanks in advance!
>
>
>
> --
> Best regards,
>
>
> WiB
> -------------------
>
>
--
View this message in context:
http://www.nabble.com/Validation-on-java.util.List-tf3398904.html#a9478828
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]