I got this completely working in a test, so if you need more help then to 
put entryId as an Integer equalling 0, let me know.  Oh, and if you couldn't 
figure this out, when you use it as an index, it will come out as an Integer 
value, and you'll need to say something like:
<td><html:text name="report" property="account[entryId.intValue()]"/></td>

Becky


----Original Message Follows----
From: [EMAIL PROTECTED]
Reply-To: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: indexing in tag 'iterate'
Date: Fri, 29 Jun 2001 18:21:38 +0200

Hi

I need a form representing a two-dimensional array of input fields.

Can anybody tell me what the appropriate solution in Struts 1.0 looks like?

Despite numerous attempts to solve this with Struts, I did not succeed. My
attempted solution (in fact, one of them) looks like that
('account', 'amount' and 'remark' are indexed properties of the Bean
represented by 'report'):

...
<table>
<tr>
<th>Account</th><th>Amount</th><th>Remark</th>
</tr>
<bean:define id="report" type="ReportForm" toScope="session"  name="select"
property="report" scope="session"/>
<html:form name="report" type="ReportForm" scope="session" action="log.do">
<logic:iterate name="report" property="entries" id="entry" indexId
="entryId">
<tr>
         <td><html:text name="report" property="account[entryId]"/></td>
         <td><html:text name="report" property="amount[entryId]"/></td>
         <td><html:text name="report" property="remark[entryId]"/></td>
</tr>
</logic:iterate>
<tr><td colspan=3><center>
     <html:submit>
       <bean:message key="button.submit"/>
     </html:submit>
</td></tr>
</html:form>
</table>

This causes the exception:

java.lang.IllegalArgumentException: Invalid indexed property
'account[entryId]'
         at
org.apache.struts.util.PropertyUtils.getIndexedProperty(PropertyUtils.java:308)
         at
org.apache.struts.util.PropertyUtils.getNestedProperty(PropertyUtils.java,
Compiled Code)
         at
org.apache.struts.util.PropertyUtils.getProperty(PropertyUtils.java:453)
         at
org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:503)
         at
org.apache.struts.taglib.html.BaseFieldTag.doStartTag(BaseFieldTag.java:188)
         at _0002freport_0002ejspreport_jsp_38._jspService
(_0002freport_0002ejspreport_jsp_38.java, Compiled Code)
         at
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at
org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:177)
         at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:318)
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java,
Compiled Code)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at
org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
         at org.apache.tomcat.core.Handler.service(Handler.java:286)
         at
org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
         at
org.apache.tomcat.facade.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:194)
         at
org.apache.struts.action.ActionServlet.processActionForward(ActionServlet.java:1758)
         at
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1595)
         at
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:509)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at
org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
         at org.apache.tomcat.core.Handler.service(Handler.java:286)
         at
org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
         at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
         at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
         at
org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp12ConnectionHandler.java:166)
         at
org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java,
Compiled Code)
         at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java,
Compiled Code)
         at java.lang.Thread.run(Thread.java:479)

If I replace the index variable 'entryId' by a literal number (see below),
this works so far (though it is not 'meaningful', ); thus the environment
(beans etc.) seems to be OK.
...
<table>
<tr>
<th>Account</th><th>Amount</th><th>Remark</th>
</tr>
<bean:define id="report" type="ReportForm" toScope="session"  name="select"
property="report" scope="session"/>
<html:form name="report" type="ReportForm" scope="session" action="log.do">
<logic:iterate name="report" property="entries" id="entry" indexId
="entryId">
<tr>
         <td><html:text name="report" property="account[2]"/></td>
         <td><html:text name="report" property="amount[2]"/></td>
         <td><html:text name="report" property="remark[2]"/></td>
</tr>
</logic:iterate>
<tr><td colspan=3><center>
     <html:submit>
       <bean:message key="button.submit"/>
     </html:submit>
</td></tr>
</html:form>
</table>

I suppose there must be a solution in Struts for this standard problem. How
does it look like?

Thanks if you can bring me on the right track.

Guido



_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

Reply via email to