Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adding Dynamic Datatable to Panel Grid

 
Mark Robert
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dusi.

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

Mark.
 
Gopu Akraju
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic