DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23465>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23465 "indexed" form data cannot be parsed by a struts DynaActionForm bean Summary: "indexed" form data cannot be parsed by a struts DynaActionForm bean Product: Struts Version: 1.1 Beta 3 Platform: All OS/Version: Linux Status: NEW Severity: Normal Priority: Other Component: Custom Tags AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] If an attempt is made to publish iterative data from a DynaFormBean in a webform, for example N line items on an invoice, this data cannot be read back again into the DynaFormBean for processing (validation / whatever). If a form bean is defined like so: <form-bean name="invoiceForm" type="org.apache.struts.action.DynaActionForm"> <form-property name="description" type="java.lang.String[]" /> <form-property name="quantity" type="java.lang.String[]" /> <form-property name="price" type="java.lang.String[]" /> </form-bean> An Action pre-populates the above data with a number of line items, the number of which is decided by the Action. Problem A: ---------- If the struts tags are rendered as follows: <logic:iterate indexId="index" id="description" name="invoiceForm" property="description" /> <html:text indexed="true" property="description" /> <html:text indexed="true" property="quantity" /> <html:text indexed="true" property="price" /> </logic:iterate> the values generated for the forms are as follows: [L.java.lang.String;@1c7e176 [L.java.lang.String;@1c7e176 [L.java.lang.String;@1c7e176 the names generated for the text fields are as follows: org.apache.struts.taglib.html.BEAN[0].description org.apache.struts.taglib.html.BEAN[0].quantity org.apache.struts.taglib.html.BEAN[0].price With this method, the values are broken, and the form displayed is corrupt. Problem B: ---------- If the struts tags are rendered as follows: <logic:iterate indexId="index" id="description" name="invoiceForm" property="description" /> <html:text indexed="true" property="<%=\"description[\" + index + \"]\"%>" /> <html:text indexed="true" property="<%=\"quantity[\" + index + \"]\"%>" /> <html:text indexed="true" property="<%=\"price[\" + index + \"]\"%>" /> </logic:iterate> the values generated for the forms are the correct values as prepopulated by the Action. the names generated for the text fields are as follows: org.apache.struts.taglib.html.BEAN[0].description[0] org.apache.struts.taglib.html.BEAN[0].quantity[0] org.apache.struts.taglib.html.BEAN[0].price[0] When the above names are submitted in the form, and struts attempts to populate the DynaActionForm bean from the values on the page, the above names are not recognised as valid entries in the bean, and are so ignored. Problem C: ---------- If an additional struts html submit tag is added to the mix, say to delete a line item from the invoice, like so: <logic:iterate indexId="index" id="description" name="invoiceForm" property="description" /> <html:submit indexed="true" property="<%=\"delete[\" + index + \"]\"%>" value="Delete" /> </logic:iterate> The name is rendered as: delete[0] If an attempt is made to submit this form using this submit button, struts attempts to populate the DynaActionForm bean. This time round, struts recognises the "delete" part as an entry in the DynaActionForm bean, and tries to set index "0" on that particular entry. However - struts has made no attempt to create a suitable String[] array inside the DynaActionForm bean, so the attempt bombs out with an ArrayIndexOutOfBoundsException. Conclusion: ----------- The most elegant way of expressing the config for the above is described in problem A above. This way there is no need for ugly scriplets to embed the index, it is all handled by the indexed="true" parameter. The fix for this seems to be: - Make the indexed="true" mechanism understand how to deal with String[]'s. - Make the name of the form come out as "description", OR make the name come out as "description[0]", but then struts must be taught how to populate a String[] correctly without throwing the ArrayLindexOutOfBoundsException. Struts already knows how to do with normal multi-valued parameters in a form. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]