aspose file tools*
The moose likes JSF and the fly likes Adding Dynamic Datatable to Panel Grid Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Adding Dynamic Datatable to Panel Grid" Watch "Adding Dynamic Datatable to Panel Grid" New topic
Author

Adding Dynamic Datatable to Panel Grid

Mark Robert
Greenhorn

Joined: Oct 04, 2007
Posts: 3
Hi,

I have to create 100s of data table dynamically and need to display it in the page. I will know the exact number of data tables only at runtime.

So my plan is to create dynamic data tables in backing bean. Then add this to a container. Then display this container in the jsf page.

For testing purpose, I created a dynamic datatable. Then I added it to a panel grid.

This is the line in backing bean where I add the dynamic data table to the panel grid.

dynamicPanelGrid.getChildren().add(dynamicDataTable);

This is what is in my jsp page.

<h:panelGrid columns="1" id="dynaPanel"
binding="#{pc_ApptTypes4.dynamicPanelGrid}">
</h:panelGrid>

When I ran the application, I can see only the headers of the datatable.
I could not see any values.

Have anyone tried this, let me know.
A. Dusi
Ranch Hand

Joined: Sep 27, 2004
Posts: 114
I had a similar requirement in my project and in addition, each datatable had different number of columns. I solved this by nested datatables approach. My JSF implementation was MyFaces and Tomahawk. So if you are flexible using these implementations, have a look at t:dataList, t:datatable, t:columns and t:column components.
Mark Robert
Greenhorn

Joined: Oct 04, 2007
Posts: 3
Originally posted by A. Dusi:
I had a similar requirement in my project and in addition, each datatable had different number of columns. I solved this by nested datatables approach. My JSF implementation was MyFaces and Tomahawk. So if you are flexible using these implementations, have a look at t:dataList, t:datatable, t:columns and t:column components.


Hi Dusi,
Thanks to your reply. Can you post a template code of .java and .jsp.

Regards,
Mark.
A. Dusi
Ranch Hand

Joined: Sep 27, 2004
Posts: 114
Have a look at the example here.
This has the source code for java and jsp.
The example given is for dynamic number of columns. You may extend this example in conjunction with a dataList component to get the dynamic tables with dynamic columns.

Actually if you do not need dynamic columns, the solution is simple with no need of t:columns complexity:
In your backing bean, make a list of all result sets(table data). In your jsp, use t:dataList (or even h:datatable I think) to loop through that list and display each result set in a h:dataTable.
You may also consider using a simple class to hold each table description and its resultSet and making a list of these objects instead of list of result sets. In your jsp you can now display the table description also.



The above code is from here.
Lets say each country object has a name and datatable of states. Then,
the code in bold font can be something like this:

Hope this helps..
[ October 09, 2007: Message edited by: A. Dusi ]
Mark Robert
Greenhorn

Joined: Oct 04, 2007
Posts: 3
Thanks Dusi.

If there is any other issue related to this, I will post.
Otherwise, Thanks again.

Mark.
Gopu Akraju
Ranch Hand

Joined: Jan 13, 2008
Posts: 242
Hi
I am also facing a very similar situation, where I am supposed to get the info from the user about the "number of columns" and generate one table with that many number of columns(rows are fixed). I am new to programming. The link you have given in that message doesn't work now. It would be really useful if you can send me some sample jsp and java files.
Thanks and Regards
Lilly
A. Dusi
Ranch Hand

Joined: Sep 27, 2004
Posts: 114
That link is now available at http://www.irian.at/myfacesexamples/dataList.jsp.source

If you have dynamic number of columns, I suggest you also look at this example: http://www.irian.at/myfacesexamples/crossDataTable.jsf

Note that these are Myfaces Tomahawk components. If you are using a different implementation, I am sure that they have similar components.
Vinaya Tirikkovalluru
Greenhorn

Joined: Feb 27, 2009
Posts: 1
Mark Robert wrote:Hi,

I have to create 100s of data table dynamically and need to display it in the page. I will know the exact number of data tables only at runtime.

So my plan is to create dynamic data tables in backing bean. Then add this to a container. Then display this container in the jsf page.

For testing purpose, I created a dynamic datatable. Then I added it to a panel grid.

This is the line in backing bean where I add the dynamic data table to the panel grid.

dynamicPanelGrid.getChildren().add(dynamicDataTable);

This is what is in my jsp page.

<h:panelGrid columns="1" id="dynaPanel"
binding="#{pc_ApptTypes4.dynamicPanelGrid}">
</h:panelGrid>

When I ran the application, I can see only the headers of the datatable.
I could not see any values.

Have anyone tried this, let me know.


Hi,
Hope you got this to work.
Can you please share the code?

Thanks
Vinaya
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Adding Dynamic Datatable to Panel Grid
 
Similar Threads
data table binding doesnot work
How to use CommandLink in custom component?
Brain burp! Can't get the right Data Grid layout
JSF dynmaic columns generation
Dynamic t:dataTable display oddness.