File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes h:dataTable and handling multiple collections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "h:dataTable and handling multiple collections" Watch "h:dataTable and handling multiple collections" New topic

h:dataTable and handling multiple collections

Preetham Chandrasekhar
Ranch Hand

Joined: Nov 05, 2003
Posts: 98
Hi All,

Here's a scenario I need help with...

I am trying to populate a table...this table has 3 columns...
1. Name of a property
2. Value of Property from entity1
3. Value of Property from entity2

The backing bean has a propertiesList which is an arraylist and this in turn has 2 property lists
1. propertyList1
2. propertyList2
which in turn are arraylists.

each property in above lists is a Property object with the name value pair...

How do i achieve this scenario using h:dataTable...

<h:dataTable id="outerTable"
| var="z"
| value="#{propertiesList}">

then what? how do I iterate through both the propertyist1 and list2 and display the values as requested above?...Lets assume the order of the names of attributes are in sync for both the lists

"In theory, there is no difference between theory and practice. But, in practice, there is."<br /> - Jan L.A. van de Snepscheut
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Well, there are a few options.

1. Create a UI Bean that will store the values you want in the table in a single collection structure. This would require more code and you looping through your two lists to combine them into one big list.

2. Use a third party JSF datatable that supports sub-tables.

3. Nest jsf datatables, the inner datatable using the var from the outertable to get to the inner list.


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
I agree. Here's the link:
subject: h:dataTable and handling multiple collections
It's not a secret anymore!