aspose file tools*
The moose likes Struts and the fly likes Sticky nested lists problem in Struts 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Sticky nested lists problem in Struts 2" Watch "Sticky nested lists problem in Struts 2" New topic
Author

Sticky nested lists problem in Struts 2

Drew Kidder
Greenhorn

Joined: Jan 26, 2010
Posts: 2
Hello, all...

I'm having trouble figuring out how to access a nested list via the <s:iterator> tag. I understand about nesting the <s:iterator> tag in my JSP, but my returned list is a little complicated.

My basic list is a list of a type called Record which is basically just a hash map. What I'm trying to accomplish is returning a list that contains some properties of a particular row in a table, and then has some sub-lists of accounts that have hit targets, missed them, or have no data. Note that in the following description square brackets ([) indicate a list and curly braces ({) indicate a Record, which is a hash map. So my basic list item looks like this:

[ {header record}, [{ item1=value, item2=value, item3=value, hits=[{account=, id=}, {account=, id=}...], miss=[{account=, id=}, {account=, id=}...] } ] ]

The hits, miss, and nodata (not shown here) could have any number of accounts or could be an empty list. The super-high level diagram of what my list looks like, taking into account that structure above, looks like this:

[main list: {header record}, [list: {items [list], [list], [list]} ], [list: {items [list], [list], [list]} ], {header record}, [list: {items [list], [list], [list]} ], ... ]


My JSP code, then, to display the data, looks like this:



For the life of me, I can't figure out how to access the list values of "account" and "id" from the "hits" and "misses" list. I've tried the following ways to access them:

<s:iterator value="hits">
<s:iterator value="#hits">
and within the code where the values are used, <s:property value="#hits.account"/> or even <s:property value="%{#hits.account}"/>

Can anyone help me figure out how to access these sub lists? I think that the main issue here is that my list isn't a straight list of lists - there are some items that I need to get for the overall row, and the sublists are just a part of that record. Any ideas would be welcomed, because I'm really at a wall here.



--
Drew Kidder
Java codeslinger and Struts 2 n00b
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I have no idea what your JSON-like stuff is supposed to represent. Sure would have been a lot easier to just pseudo-code the actual Java object(s) you're sending.

If you're using a list as a poor-man's object, I wouldn't iterate over the "meta"-list, but access its elements directly. But this is, in general, a Bad Idea. Send an object that exposes the lists: keep it clean.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sticky nested lists problem in Struts 2
 
Similar Threads
Iterating in jsf
Update Database with the newly entered value
Struts2 test condition in s:if not working
How to do s:if test of a value in the iterator?