原帖地址:http://www.coderanch.com/t/55846/Struts/Using-attribute-indexedListProperty-field-tag
Hi ranchers,
Iam using Validator framework, in one of the form,I have a List which contains Lastname,firstname etc, here I need to to validate these fields..
following is the example code....
<form name="XYZForm">
<field property="lastname" depends="required,mask" indexedListProperty="XYZListObject">
Its not working properly,what are the things to do to make it work properly using indexedListProperty...
Thanks in advance.
----------------------------------------------
Hi Merrill,
Yes, indexedListProperty is supported in Struts and I have used it successfully. If you specify indexedListProperty="XYZListObject", it is expected that the actual property name for the first element will be "XYZListObject[0].firstName", If that is not the case, the validation will not be performed. Be careful with case. Remember that if your getter is getXYZListObject, the property name used by Struts will be "xYZListObject" not "XYZListObject".
can you please give an example code,or correct this to make it work,this is what iam using in validation.xml...
<form name="IPForm">
<field property="lastname" depends="required,mask" indexedListProperty="pListObject">
<arg0 key="lastname" />
<msg name="mask" key="errors.addpax.LastName.required"/>
<var>
<var-name>mask</var-name>
<var-value>^[a-zA-Z ,]*$</var-value>
</var>
</field>
</form>
Thanks in advance,
RR
------------------------------------------------------
I wouldn't be able to tell is your code is correct or not without also seeing your ActionForm bean, the relevant portion of your struts-config.xml file, and the relevant portion of the JSP.
Here is code from a sample page that I have tested and can verify that it works.
struts-config.xml
- ...
- <form-bean name="testRatingForm"
- type="org.apache.struts.validator.DynaValidatorForm" >
- <form-property name="testField" type= "java.lang.String" initial= "" reset= "true" />
- <form-property name="choices" type= "java.lang.String[]" initial= '{"1", "2", "3", "4", "5" }' />
- <form-property name="criteria" type= "java.lang.String[]" reset= "true" initial= '{"", "", "", "", "", "", "" }' />
- </form-bean>
- ...
- <action path="/testRating"
- type="org.merrill.actions.TestRating"
- name="testRatingForm"
- scope="request"
- validate="true"
- input="/testRating.jsp" >
- <forward name="success" path= "/testRating.jsp" ></forward>
- </action>
validation.xml
- <form name= "testRatingForm" >
- <field
- property="testField"
- depends="required,mask" >
- <arg position="0" key= "test field" resource= "false" />
- <arg position="1" key= "must by a,z" resource= "false" />
- <var>
- <var-name>mask</var-name>
- <var-value>^[a-zA-Z]*$</var-value>
- </var>
- </field>
- <field
- indexedListProperty="criteria"
- property="criteria"
- depends="required" >
- <arg key="criteria" />
- </field>
- </form>
testRating.jsp
- <html>
- <head>
- <meta http-equiv="Content-Type" content= "text/html; charset=ISO-8859-1" >
- <title>Test rating chart</title>
- </head>
- <body>
- <html:form action="/testRating" >
- Test Field <html:text property="testField" />
- <table border="1" >
- <tr>
- <th>Criteria</th>
- <th>poor</th>
- <th>fair</th>
- <th>average</th>
- <th>good</th>
- <th>excellent</th>
- </tr>
- <logic:iterate id="criterion" name= "testRatingForm" property= "criteria" indexId= "x" >
- <tr>
- <td>criterion <%=x %></td>
- <logic:iterate id="choice" name= "testRatingForm" property= "choices" type= "java.lang.String" >
- <td>
- <html:radio property='<%="criteria["+x+"]" %>' value= "<%=choice %>" />
- </td>
- </logic:iterate>
- </tr>
- </logic:iterate>
- </table>
- <html:errors />
- <html:submit value="OK" />
- </html:form>
- </body>
- </html>