This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Struts and the fly likes Struts2 Iteator Tag with object in object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 Iteator Tag with object in object" Watch "Struts2 Iteator Tag with object in object" New topic
Author

Struts2 Iteator Tag with object in object

Srinivas Anumala
Greenhorn

Joined: Dec 22, 2004
Posts: 5
Hi
I have following data structure in my action class.



Action class has list of reports.

List<Report> reports;

I have created list in action class and trying get the values in JSP using <s:iterator> tag.

I am able to get report.id value... but could not get "report.user.name" value

Any suggestion how to retrieve "report.user.name" value in iterator tag .


Thanks

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Code please.
Srinivas Anumala
Greenhorn

Joined: Dec 22, 2004
Posts: 5
Here are the code details.

User Class:




Report Class:



Action Class:



In JSP, using the following iterator tag to retrieve the data from list:




Please suggest how to retrieve "report.user.name" in this case ? Thanks
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I don't see anything obviously wrong, but I'm distracted at the moment.

Try assigning each report to a variable and accessing it directly using the iterator tag's "var" or "id" attribute (depends on S2 version) first.
Srinivas Anumala
Greenhorn

Joined: Dec 22, 2004
Posts: 5
Hi david,

I have tried using iterator tag as shown below.

This also giving me only id, but did not work



David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

What version of Struts?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That code won't even compile--are you sure you're deploying what you think you are?

If that's not the actual code, then save us both some time--post accurate information.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

And the action configuration.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

It's working fine for me with your original code--your compilation issues might be a problem.
Srinivas Anumala
Greenhorn

Joined: Dec 22, 2004
Posts: 5
I am using Struts 2.1.8.

Its compiled for me and no compilation errors using both versions of tag code.

Please let me know which version you are using and tag code which you used.

Thanks

Srinivas Anumala
Greenhorn

Joined: Dec 22, 2004
Posts: 5
Hi David,

Thanks for your time. Please ignore my last comment.

Its resolved.

Thanks
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

It's polite to include what the issue was in the followup, but I'm glad you got it resolved.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Srinivas Anumala wrote:Its compiled for me and no compilation errors using both versions of tag code.

There is *no* possible way the code you posted above compiled.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts2 Iteator Tag with object in object