Hi,
I have a form-property like so: <form-property name="PropertyName" type="java.lang.String[]" size="5"/>
Which is populated by the following in my jsp page:
<logic:iterate id="element" name="MyForm" property="PropertyName" indexId="counter"> <tr> <td class="firstCol"><bean:message key='MyForm.PropertyName'/>:</td> <td class="lastCol"> <html:select property='<%="PropertyName[" + counter + "]" %>'> <html:option key="select.default" value=""/> <logic:notEmpty name="MyForm" property="PropertyName_refData"> <html:options property="PropertyName_refData" ></html:options> </logic:notEmpty> </html:select> </td> </tr> </logic:iterate> <tr> <td> </td> <td> <html:errors property="PropertyName"/> </td> </tr>
This works fine as I get the 5 html:selects on the page. However, I want to validate this and check that at least 1 of the 5 have been specified. I've tried the following in validation.xml but am getting unexpected token errors and I can't figure out how to do my validation.
<field property="PropertyName" indexedListProperty="PropertyName" depends="validwhen"> <arg0 key="MyForm.PropertyName"/> <var> <var-name>test</var-name> <var-value>((PropertyName[0] != null) or (*this* != null))</var-value> </var> </field>
Any suggestions as to how I can validate that at least 1 has been specified would be most welcome!
Paul - when using indexedListProperty in a field for validator, indexedListProperty is the name of the *form-property* from struts-config that you want to validate and property becomes the property *of that class* that you want to validate.
In what you have posted above, this would mean that validator is trying to validate PropertyName[x].PropertyName - because PropertyName[x] is a String object though, there is obviously no PropertyName in it.
I have never seen indexedListProperty used with a String object before, and am not entirely sure it is possible. I think the type of the object you use for your indexedListProperty must have a getter/setter for whatever property you use, and String fails that test. (Maybe somebody else will chime in and prove me wrong though...)
I think the bigger question is - if you are using a set size String array for these fields, why not just simplify it and make 4 separate fields? You don't need to worry about indexed properties at all then.
The only alternative I can think of is to setup a new class, and make an array of that.
Matt
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]