• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to iterate over one List and get a nested property defined in a different List

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm in a struts/tiles world and having some difficulty doing this in reusable fashion.... I have a List of rows that contain cells/columns. I want to iterate over the rows and then iterate over the cells and get a value from the row's cell. Different tables all have rows, but the cells and the getters for those cells are different for each table. How can I generically get the the cell's value (which is stored in the row). To help myself out I get to define the List of cells.

Inside the row loop I loop over columns (using the id column) and I can use an expression to specify the property of the row that I want:
<bean:write name="row" property="<%= column %>" />
that works just fine. The draw back being that I am defining the ArrayList (that "map" the this particular tables columns) in the jsp that I want to generically iterate. I would have to repeat the looping code for each table, that would be bad.

What I think I would prefer (I'm open to alternatives), is to define the columns in a a putList (that I have named columnNames) in the tiles insert that defines the rest of the page. This makes sense to me. And it does in pass my list to the appropriate JSP. But the problem is that I can't use the putList values in the bean:write tag.

<bean:write name="columnName"/> <%-- this works - and outputs the column name, but not the value of in the column of the in the row with that name --%>

I have tried several variations to no avail. Any help would be greatly appreciated. I have posted the full source of the jsp with the loop as well as the source of the jsp doing the tiles insert below. Not posted is the layout page that has one contributing tag:

Also it's worth noting that inside the row loop I loop over the ArrayList of columns and then within that I loop over the putList columns. This is only for convenience while testing and switching back and forth, obviously it will be one or the other looping over the columns just once (preferable the putList).

customerExposureByRiskRating.jsp




grid-headerTable-exposure.jsp
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"acklenx", please check your private messages for an important message from me.
 
Quincy Acklen
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what I came up with. It still uses scriplets, but it does allow me to use a putList (which defines the rows _where_ I want - in the first/top tile jsp) to get values out of another object that is being looped upon. Now the code can be reused by any table/grid.

But how do I get rid of the scriptlet?

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Quincy.Acklen", please check your private messages again.
 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Bear Bibeault,

Could you please post the answer here to share with others? I think private message is not for open source.

I have similar questions about Struts.

Regards,

Sam
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sam,

When a Sherrif, Bartender or other administrator indicates in a thread that he/she is sending a private message to an individual, you can be certain that it is not private information about the topic, but rather some administrative detail such as compliance with the naming policy and other matters of conern only to the individual, and not to the forum at large.

Merrill
 
If you want to look young and thin, hang around old, fat people. Or this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic