This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Struts and the fly likes struts 2.0 iterator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts 2.0 iterator" Watch "struts 2.0 iterator" New topic

struts 2.0 iterator

Sekhar Chand
Ranch Hand

Joined: Apr 05, 2006
Posts: 73
Hi friends,

i am working in struts 2.0, just started today.
I have one class which contains 8 attributes.
I have to add different objects of that class in a list.
I have to populate that list in a jsp page.
Means getting those list and iterating through list , i have to get those different attributes of objects.
i have to present all the attributes of one object in a single row.
And for different object in different rows.
For this in struts 1.2 , i have to add that list in session , and in jsp page , using logic:iterate i can do.
But i don't know know how to do in struts 2.0
Please help , i have to do this immediately..

Thanks in advance
Wes Wannemacher

Joined: Jul 07, 2007
Posts: 13
I am not sure if this is what you are looking for, but I have a post on my blog that contains an example of using <s:iterate>, you can see it here ->

Writing and Configuring Struts2 Actions

The code sample on this page that does it is called GuestBook_messages.jsp. I would suggest reading the whole post though because it will contain other helpful tidbits.


Discussion of Java, Struts, Spring, Hibernate, etc.

Discussion of Java, Struts, Spring, Hibernate, etc. <a href="" target="_blank" rel="nofollow"></a>
Sekhar Chand
Ranch Hand

Joined: Apr 05, 2006
Posts: 73

hey wes your link is not working properly.
Actually my requirement is:
i have one java bean, in that bean i have 8 properties.
In runtime i will get number of objects for that bean from database.
i have to populate all the fields in a table like one object in one row and one proeprty in one column.

take an example of emp table, i have a java bean of emp with those attributes.
i want to populate those different employees. like that table

thanks in advance
ratna sekhar
Wes Wannemacher

Joined: Jul 07, 2007
Posts: 13
Darnit, I wonder what I did wrong... Oh well, basically, it works like this. Your collection of objects has to implement the java.util.List interface (such as a Vector). Then, you can place a public Vector<Emp> getEmp() method in your Action. Then when you use the s:iterator tag, you tell it that you want to iterate over "emp." The tag will place one of your objects on the value stack for each iteration, which will make the attributes of your Emp class available to s:property.

Here is the code from my example -

In my example, I have a method in my action that looks like this -

The getMessages method makes the Vector available on the value stack, the s:iterator tag finds that method when I say value="messages."

-Merrill Cleaned up the smileys
[ July 09, 2007: Message edited by: Merrill Higginson ]
Wes Wannemacher

Joined: Jul 07, 2007
Posts: 13
cripe! those smileys made that post hard to read... the article is available here -

You'll have to copy/paste the url, I need some practice with UBB Code before I try to make it a real link.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864

I cleaned up the smileys for you this time.

In the future, if you want to get rid of those annoying smileys, go back to your post and click the edit button (The pencil and paper icon). Then scroll down to the options section of the page and check the checkbox labeled "Disable smilies in this post".
[ July 09, 2007: Message edited by: Merrill Higginson ]

Consultant, Sima Solutions
Have you checked out Aspose?
subject: struts 2.0 iterator
jQuery in Action, 3rd edition