Tuesday, January 29, 2008

Multiple Line JSF Data Tables

Ok, so you need to create a multi row data table right? Now you want to do this with JSF and you see that you're up a creek without a paddle. This doesnt fit the norm for most "grid" layouts on the web. The standard JSF just doesnt allow for this with a datatable but you can use the panelgrid to get the results that you want. Here is how.



Why don't we break this down to see what we do here.

Line 1 is our standard data table layout using the backing bean reportListingReports.claimsToWork

There is nothing new here, standard call to a backing bean for the JSF information. We set the variable ctwb for use in the column.

Line 5 is where we introduce the column. As you can see here the matching tag for this is at line 25. We use one column so we continue to iterate through our row data.

Line 6 introduces our panel grid. We use this to construct the real table here. We continue to go down through the panelgrid and output the different elements using the ctwb variable.

Line 22 closes out the panelgrid.

Line 23 gives us a summary row underneath. I use this for outputting a status message on the previous row but you could introduce another panelgrid or whatever you like here.

So to summarize what we have here is 2 visible rows of data on the screen. Presentation goes something like this.
ROW1COL1     ROW1OL2    ROW1COL3
ROW2BUT BUT IS PART OF DATA ROW 1

ROW2COL1     ROW2OL2    ROW2COL3
ROW3BUT BUT IS PART OF DATA ROW 2


You should have the idea. This gives nice formatting for anyone that needs to output a text description on the row but doesnt have the space on the screen (or in the data table column.

Now, remember you'll need to use the column classes and style the table correctly or this may not look just right for you. It is easy enough to acomplish with some css code.

2 comments:

Anonymous said...

If you also pasted the backing bean code, it would more clear of which datat is shown in which rows....

Yellow Blade said...
This comment has been removed by a blog administrator.