aspose file tools*
The moose likes Struts and the fly likes Iterate a String array in Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Iterate a String array in Struts" Watch "Iterate a String array in Struts" New topic
Author

Iterate a String array in Struts

Kavita Chhabria
Greenhorn

Joined: Aug 11, 2005
Posts: 4
Hello All:

I have the following requirement:

I have a String array in java called String[] ListOfNames.

Each element in ListOfNames is again an array containing First Name, Middle Name and Last Name of individuals.

So, in other words, it is an array of arrays.

How do I iterate over this ListOfNames in struts such that, each internally contained string array is displayed as a single row in a table and as we iterate over the String array, for every new array contained within it, I am showing it as a new table row on the jsp page.

I hope I have my requirements clear.

Please ask for more explanation if needed.

Also, pls send me a soln to the above problem as soon as possible, I need this help urgently on my project.

Thanks a lot,

Kavita Chhabria
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
You will just two <logic:iterate> tags nested one in another.
Pseudo code:
<logic:iterate> <%-- Iterate over ListOfNames --%>
<logic:iterate>
Print inner array
</logic:iterate>
</logic:iterate>


SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

I have a String array in java called String[] ListOfNames.

Each element in ListOfNames is again an array containing First Name, Middle Name and Last Name of individuals.

Wouldn't that make listOfNames (which should be lower-case 'l', not 'L') a String[][]?


A good workman is known by his tools.
Robin Sharma
Ranch Hand

Joined: Aug 24, 2005
Posts: 76
Hi Kavita!

As Marc pointed out, you need to follow the bean law while naming variables in your ActionForm. So, assuming that the variable is called listOfNames, the following code should work fine:

<table border="1">
<logic:iterate id="outer" name="<Form key name>"
property="listOfNames">
<tr>
<logic:iterate id="inner" name="outer">
<td>
<bean:write name="inner"/>
</td>
</logic:iterate>
</tr>
</logic:iterate>
</table>


DW
There is always a bug :-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Iterate a String array in Struts