wood burning stoves 2.0*
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
Author

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
Sekhar
Wes Wannemacher
Greenhorn

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.

-Wes

--
Discussion of Java, Struts, Spring, Hibernate, etc. http://www.wantii.com


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

Joined: Apr 05, 2006
Posts: 73
Hi,

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
Greenhorn

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
Greenhorn

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

http://www.wantii.com/wordpress/?p=13

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
Wes,

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 ]

Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: struts 2.0 iterator
 
Similar Threads
RequestDispatcher and setAttribute
When using MVC, to what degree should a model be tailored to a view?
Problem with 2 ActionForms for one JSP
How do u pass an object to a taglib from a jsp?
Actionservlet is model or controller