This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "h:dataTable and handling multiple collections" Watch "h:dataTable and handling multiple collections" New topic
Author

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
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

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.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
jQuery in Action, 2nd edition
 
subject: h:dataTable and handling multiple collections