<logic:iterate> tag

T

TheVooDooChild

I have an object called "Branch" that contains a String branchName,
ArrayList barcodeList, and an ArrayList itemNumberList. I have a form
that is initialized with an array of Branches, and the ArrayLists
within them are initialized with empty strings (""). This allows me to
use the <logic:iterate> tag to create 1 row per branch and the correct
number of empty text fields needed for barcodes and itemNumbers within
that branch. All works fine until the JSP is submitted. When I fill
out the text fields and submit, I end up with only 1 Branch object in
the form, which was the 1st row on the jsp. So I get Branch[1],
barcode[1], and itemNumber[1].

Any ideas why I'm losing the rest?


I am using the struts <logic:iterate> tag in the following way:


<logic:iterate id="branch" name="FrmCustomerHolding"
property="branches" type="com.company.bdm.common.Branch" >
<tr>
<td align="left" valign="top">
<b><bean:write name="branch" property="branchName" /></b>
</td>

<td align="left">
<logic:iterate id="barcode" name="branch" property="barcodeList"
indexId="idx" type="java.lang.String" >
<logic:notEqual name="idx" value="0" >
<br>
</logic:notEqual>
Barcode <%= idx.intValue() + 1 %>:&nbsp; <html:text
property="barcode" />
</logic:iterate>
</td>

<td align="left">
<logic:iterate id="itemNumber" name="branch"
property="itemNumberList" indexId="idx" type="java.lang.String" >
<logic:notEqual name="idx" value="0" >
<br>
</logic:notEqual>
Item # <%= idx.intValue() + 1 %>:&nbsp; <html:text
property="itemNumber" />
</logic:iterate>
</td>
</tr>
</logic:iterate>
 
W

Wendy S

TheVooDooChild said:
All works fine until the JSP is submitted. When I fill
out the text fields and submit, I end up with only 1 Branch object in
the form, which was the 1st row on the jsp. So I get Branch[1],
barcode[1], and itemNumber[1].

Any ideas why I'm losing the rest?

Because the html you're generating does not include the index.
<html:text property="itemNumber" />

Doesn't that generate a bunch of <input type="text" name="itemNumber">
tags? Printing the line number to the left doesn't do anything for Struts.

I think they need to look like this:
<input type="text" name="itemNumber[1]"> in order for Struts to populate
your arrays.

Google for 'Struts Indexed Properties'.
 
S

Steve Bosman

TheVooDooChild said:
I have an object called "Branch" that contains a String branchName,
ArrayList barcodeList, and an ArrayList itemNumberList. I have a form
that is initialized with an array of Branches, and the ArrayLists
within them are initialized with empty strings (""). This allows me to
use the <logic:iterate> tag to create 1 row per branch and the correct
number of empty text fields needed for barcodes and itemNumbers within
that branch. All works fine until the JSP is submitted. When I fill
out the text fields and submit, I end up with only 1 Branch object in
the form, which was the 1st row on the jsp. So I get Branch[1],
barcode[1], and itemNumber[1].

Any ideas why I'm losing the rest?


I am using the struts <logic:iterate> tag in the following way:


<logic:iterate id="branch" name="FrmCustomerHolding"
property="branches" type="com.company.bdm.common.Branch" >
<tr>
<td align="left" valign="top">
<b><bean:write name="branch" property="branchName" /></b>
</td>

<td align="left">
<logic:iterate id="barcode" name="branch" property="barcodeList"
indexId="idx" type="java.lang.String" >
<logic:notEqual name="idx" value="0" >
<br>
</logic:notEqual>
Barcode <%= idx.intValue() + 1 %>:&nbsp; <html:text
property="barcode" />
</logic:iterate>
</td>

<td align="left">
<logic:iterate id="itemNumber" name="branch"
property="itemNumberList" indexId="idx" type="java.lang.String" >
<logic:notEqual name="idx" value="0" >
<br>
</logic:notEqual>
Item # <%= idx.intValue() + 1 %>:&nbsp; <html:text
property="itemNumber" />
</logic:iterate>
</td>
</tr>
</logic:iterate>

See Dynamic Indexes for Indexed Properties at
http://struts.apache.org/faqs/indexedprops.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top