If I understand the situation, you might be able to do this with an array of orderItem beans (orderItems), with getName and getValue methods.
 
<logic:iterate name="orderItems" id="orderItem" >
 <tr>
 <TD> 
   <form:text name="orderItem" />
  </td> 
  </TR>
</logic:iterate>
 
form:text should then call getName and getValue for the name and value of each text field.
 
getName might use and internal counter to give the text fields different names.

*********** REPLY SEPARATOR ***********

On 12/26/2000 at 3:50 PM Chandan Kulkarni wrote:

I am trying to use <logic:iterate> to iterate through a list of order items.
I cannot get it to work. I have seen several emails about patches for handling nested and indexed properties...
 
OrderForm consists of an ArrayList of items.
 
I have added indexed getters
   ArrayList getItems()
 and
   OrderItem getItems(int index)
 
I can't see how an indexed setter would help for setting the properties of OrderItems.
  
Here are parts of my orderform.jsp
==============================================================
 
<form:form action="orderform.do" name="orderform" type="OrderForm" >
 

<TABLE>
<TR>
<TD> Order Number : </TD>
<TD> <form:text name="orderform" property="orderNumber" />  </TD>
</TR>
      
...
<% int count=0; %>
<logic:iterate id="orderlist" name="orderform"  property="items" length="2">
 <tr>
 <TD> 
   <form:text name="orderlist" property="itemNumber"
            value="<%= ((OrderItem)orderlist).getItemNumber() %>" />
  </td>
 
  </TR>
<% count++; %>
</logic:iterate>
 
<form:submit/>
</form:form>
==============================================================
 
Unfortunately this generates input tags with identical names for each iteration. This is a problem when you try to set the properties in the items.
The value= part of the <form:text> tag is a hack to get the values from the Bean.
 

Since the name generated needs to be unique I replaced the form:text lines with input tags like this:
 
    <input TYPE="TEXT" name="<%= "items.itemName[" + count++ + "]" %>" value="<%= ((OrderItem)orderlist).getItemName() %>"  />
 
the run-time expression used above cannot be used in the form:text property value, so you have to use the input tag.
 
This still does not allow for setting the values in the OrderItem...
 
Also what do you think of the name used above...
should it be
   items[0].itemName (more semantically correct - I think)
 
or should it be
   items.itemName[0]...
 
I have tried both but that doesn't work...
 
Does anyone have any pointers/suggestions to get this to work...?
 
Thanks in advance....
 
   -Chandan

Reply via email to