This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display data using Structs Tag

 
Jobin Mathew
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Dom Lassy
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic