Monday, January 07, 2013

RichFaces 4.2.x: Unique <rich:dataTable/> Design

In my current job, I have opportunities to do Proof-of-Concept for various new JSF ideas for our products. I often do a lot of these general experiments on my own time after hours at home. That is not unusual I would imagine for most developers. A couple of months ago I was tasked with trying to generate a table dynamically using RichFaces 4. In RichFaces 3, you could provide dynamic columns and have it generate the table columns and data dynamically. This functionality is currently not available in RichFaces 4.2.

I came up with a strange amalgamation of bed-mates which worked. It is an interesting approach to getting around various problems encountered developing tables.

An additional requirement was the ability to sort the data displayed in the table. Since our application at work does BI analytics, doing server side sorting is much slower and expensive than doing it client side. This problem was partially solved with JQuery and a plugin called TableSorter. I think it will work on most basic tables, and this one... well is no different.

Are you ready for some magic?

Data Table Design #3

Now that you have a chance to look at the XHTML file, I am sure you noticed some strange things like a mix of <c:forEach/> wrapping a number of <rich:column/> components inside a <rich:dataTable/>. This is the normal configuration that you might see. Also, we have added a <rich:jQuery/< component along with our JavaScript. Yes, it works. The data is pulled from JPA and displayed. It also elegantly sorts on all of the columns. The only strange code is the EL code in the <c:forEach/> for the items attribute. Since the <c:forEach/> is expecting an array, or a Collection (List) to iterate over, we must provide it a customer in that format.

I thought about deleting the design, but it actually works and may help someone solve a problem so I am publishing it.

I will publish all of the other designs once they are cleaned up in project for download.


Rudy said...

Isn't time that other JSF Component libraries are considered that have all these kind of functionalities by default? RichFaces is no longer my default choice.

John Yeary said...

We have a couple of different implementations we use. Originally, the project was using PrimeFaces, but a business decision was made to go to RichFaces.

PrimeFaces is very nice and offers a lot of great out of the box functionality. That is without question.

RichFaces is still a great JSF framework especially in the business environment where a lot of the *magic* of PrimeFaces is not required.

All of the JSF frameworks, still have really poor support for HTML tables. Some are better than others. The HTML table component is the most complex element in HTML. In fairness, you must make design decisions to handle its complexity.

I have my own JSF table component that makes tables like stacking legos, but it still has some issues with complex layouts.

Popular Posts