This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes Display data using Structs Tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Display data using Structs Tag" Watch "Display data using Structs Tag" New topic
Author

Display data using Structs Tag

Jobin Mathew
Ranch Hand

Joined: Oct 17, 2006
Posts: 83
Hi,
I want to show some data in Jsp using structs tag.
My data is in ArrayList which contains number of ArrayLists.

ArrayList table = new ArrayList();

for(int i=0;....)
{
ArrayList row = new ArrayList ();
row.add(i);
row.add("ID "+i);
table.add(row)
}

Here I had the entire data in ArrayList 'table '
How can I display it in JSP. What should I give for property = ???



<logic:iterate id="row" name="table">
<tr>

<td><bean:write name="row" property="???"/></td>

</tr>
</logic:iterate>


Thanks in Advance.
Dom Lassy
Ranch Hand

Joined: May 05, 2006
Posts: 181


The output would look like this:


If this doesn't work, post the results because I didn't test this at all.
Jobin Mathew
Ranch Hand

Joined: Oct 17, 2006
Posts: 83
Hi, This is working.

But for the first value of inner ArrayList, I need to draw a check box.
anf for rest of all, I want to display the values. So in the inner loop (iterate), i need to distinguish between first iteration & the next iterations. How can I do this?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
In order to answer this question, we'd need to know what the checkbox represents. Is it a single boolean value for each row? or do you want to store an array of values, with each checked box representing one item in the array?


Merrill
Consultant, Sima Solutions
Dom Lassy
Ranch Hand

Joined: May 05, 2006
Posts: 181
It seems to me like you should be using a list of objects instead of a list of lists where you conditionally display a checkbox based on the index of the inner loop.
Jobin Mathew
Ranch Hand

Joined: Oct 17, 2006
Posts: 83
Hey not like that.

Lst us see the arrayList
[ [1,ABC,18], [2,TRE,20], [5,REYT,30] ]

Here I want to draw checkboxes with values 1,2,5

And need to display other values. Like

Select Name Age
==============================
ckbx value=1 ABC 18
ckbx value=2 TRE 20
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I agree with Dom that it would be better to have a list of Objects. For example, suppose you create a class called Customer with properties customerNumber, name, and age. Your Actionform would then have a property called customers of type Customer[].

Then in your JSP, your code would look like this:



Note that your ActionForm will have a property named selectedCustomers of type String[].
Jobin Mathew
Ranch Hand

Joined: Oct 17, 2006
Posts: 83
Hey,
I am not iterating a DTO class.

I ma iterating a ArraList that contains many ArrayList.
Look this

ArrayList table = new ArrayList();
for(int i=0;....)
{
ArrayList row = new ArrayList ();
row.add(i);
row.add("ID "+i);
table.add(row)
}



So I need identify the first iteration.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Display data using Structs Tag
 
Similar Threads
Retrieving data using iterate and eliminating duplicate values
logic:iterate
help with html radio tag
Data display in table usinf logic:iterate tag
Arraylist in JSP with Html radio