Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

struts 2.0 iterator

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sekhar Chand
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic