File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes How to iterate over one List and get a nested property defined in a different  List Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to iterate over one List and get a nested property defined in a different  List " Watch "How to iterate over one List and get a nested property defined in a different  List " New topic
Author

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

Quincy Acklen
Greenhorn

Joined: Aug 15, 2002
Posts: 12
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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

"acklenx", please check your private messages for an important message from me.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Quincy Acklen
Greenhorn

Joined: Aug 15, 2002
Posts: 12
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

"Quincy.Acklen", please check your private messages again.
Sam Sunamin
Ranch Hand

Joined: Mar 16, 2007
Posts: 113
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


Yours Sam<br />SCJP5.0 97%<br />SCBCD5.0 72%
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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


Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to iterate over one List and get a nested property defined in a different List