This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Sticky nested lists problem in Struts 2  RSS feed

Drew Kidder
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
David Newton
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!