Wednesday, April 01, 2009

JSF 1.2: Visual JSF ( Project Woodstock) Table Row Striping, or Alternating Row Colors

I recently encountered some issues with setting the class attribute of my table rows using Javascript on Internet Explorer, and Firefox 3.0.8. The class was designed to change the background of the <td> elements of my table. I finally decided that I would try using the TableRowGroup styleClasses tag to try to accomplish the "striping", or alternating the color of odd and even rows in the table. The tag description indicates that it is as easy as adding two style classes which will accomplish this. This is not quite true if you have tried it.

The CSS for the table component in Woodstock has defined a background-color of white (#FFFFFF). This makes overriding it quite difficult.
I accomplished overriding it by placing the same element in the stylesheet.css file located in the project.

Here is what I added:
I then added my new css classes to the TableRowGroup as seen below.



The final result was to produce an elegent table with alternating colored rows.



Here is a link to the NetBeans 6.5 project on BitBucketTableAlternateRowStriping

4 comments :

Rick said...

Great info John! Any idea how to change the ugly blue color for selected rows?

Thanks!

John Yeary said...

I looked briefly at the code that changes the selected row criteria. It looks like it sets a new class for the row and elements to change the color to "UNC "Tar Heel Blue", but I don't see where to change it immediately.

CIEMME said...

Hi all,
I agree with Rick saying tath's a great info...
Is there any way to highlight a row on mouse over?

Rams�s L�pez said...

Works great! thanks for the info, was stumped on this for a while :D

Popular Posts