I hope there exists a simpler solution, but here is my workaround: use an
expression validator.
This idea was taken from 
http://www.opensymphony.com/webwork/wikidocs/collection%20validator.html
webwork wiki: collection validator  (it seems that the collection validator
is not yet available in struts).

For example, if you want to say that lastName is a requiredString, then you
can create an expression validator like this:

<validator type="expression">
   persons.{#this.lastName.length() > 0}.{? #this == false }.size() &lt;= 0
   <message>lastName cannot be empty</message>
 </validator>

which means: the size of the sub-collection of persons that does not satisfy
the condition "lastName.length>0"  must be <=0.



Julio Alberto Jalón wrote:
> 
> 
> May I didn't explain myself correctly. What I would like to know is how to
> validate multiple fields.  I'll write an example. I have a form in a JSP
> which generate the field dynamically. E.g: 
> 
> <s:form action="editPerson" theme="simple" validate="false">
>     <table>
>         <tr>
>             <th>ID</th>
>             <th>First Name</th>
>             <th>Last Name</th>
>         </tr>
>         <s:iterator id="p" value="persons">
>             <tr>
>                 <td>
>                     <s:property value="%{id}" />
>                 </td>
>                 <td>
>                     <s:textfield label="First Name"
> name="persons(%{id}).name" value="%{name}" theme="simple" />
>                 </td>
>                 <td>
>                     <s:textfield label="Last Name"
> name="persons(%{id}).lastName" value="%{lastName}" theme="simple"/>
>                 </td>
>             </tr>
>         </s:iterator>
>     </table>
> 
>     <s:submit method="save" value="Save all persons"/>
> </s:form>
> 
> 
> 
> Where person is a List in the action class. Now, what I would like to know
> is how could I achieve this fields to be validated. For example, I would
> like that if the name is filled the last name should be also filled and
> both can only contains letters and blanks. 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Struts2-Collection-validation-tp19991675p20068978.html
Sent from the Struts - User mailing list archive at Nabble.com.


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

Reply via email to