Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Datatable configuration

 
leonardo battagli
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

We want to personalize a datatable and looking for the better way.

our backing bean property is an ArrayList of n elements, each element has to be rendered with a different view, this is to say the first element has to be rendered with 2 columns, the second with 4, the last with only one.

- datatable offers only f:column (this is to say you have not control over <tr>
- datatable con be used with nested panelgrid (each row then needs a different class style)
- datatable with nested f:verbatim

which could be best solution?

Leonardo
-
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18276
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Datatable is great for vanilla stuff, but this is more than it can handle.

You'll either need to create your own custom JSF control that can do variable-column tables (spanning columns) or locate the HTML JSF libary that lets you construct raw HTML on a JSF page. Unless you're lucky enough to find something pre-built that I don't know about.

Custom JSF tags are based on the JSP tag architecture.
 
Ryan Lubke
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by leonardo battagli:
Hi all,

We want to personalize a datatable and looking for the better way.

our backing bean property is an ArrayList of n elements, each element has to be rendered with a different view, this is to say the first element has to be rendered with 2 columns, the second with 4, the last with only one.

- datatable offers only f:column (this is to say you have not control over <tr>
- datatable con be used with nested panelgrid (each row then needs a different class style)
- datatable with nested f:verbatim

which could be best solution?

Leonardo
-


I would suggest using a more robust table component. Have you looked at
Woodstock [1]?

[1] https://woodstock.dev.java.net
 
leonardo battagli
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I resolved with nested panelgrid (each row then needs a different class style)

thks
 
Jimmy Ho
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure I completely understand the issue you're trying to solve, but you could also concatenate different dataTable's together. That is, if you have 3 rows of one style, then 5 rows of another, then 1 row of yet another, then have 3 dataTable tags, one after another (or 9). If you end up doing this, JSTL libraries integrate fairly well with JSF, and you can use their routines to loop through your data, plopping down dataTables as it iterates. There are some pitfalls (for example, if you have a checkbox in each row, and if JSF doesn't know you're using a loop, it might label each checkbox with the same JavaScript name, or whatever. Check the book "Core JavaServer Faces" by David M. Geary; there's a section there on how to avoid these pitfalls).

I also like the nested panelgrid idea. Another idea is to nest dataTables, but that may be overkill for your situation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic