Actually OrderItem is an object with several fields. I trimmed it down to just one field to simplify the problem. So "items" is an ArrayList of OrderItems.
 
I couldn't find the right combination of nested/indexed property names for the form:text tag to generate the correct input tag. Here's what I tried...
 
<form:text name="orderItems" property="<%= "orderitems[" + count + "]" %>"
            value="<%= ((OrderItem)orderlist).getItemNumber() %>" />
When it can't find the correct property name in the bean it gives a compilation error. I used a run-time expression to create items[0].itemName. In this case the form:text tag is just ignored and is left in the html generated just as is...
 
It seems the only way to use an indexed/nested property name is to use the <input> tag itself.  
 
I am using the struts 12/15 build.... 
 
Thanks,
 
    -Chandan  
-----Original Message-----
From: Ted Husted <[EMAIL PROTECTED]>
To: Struts List <[EMAIL PROTECTED]>
Date: Tuesday, December 26, 2000 4:32 PM
Subject: Re: Help: <logic:iterate> and form input fields

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