O'Reilly logo

PrimeFaces Cookbook by Mert Çalışkan, Oleg Varaksin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Conditional coloring in dataTable

The dataTable component provides conditional coloring on rows, which can be styled based on conditions.

How to do it...

A basic definition of a color-coded table that displays a list of cars follows:

<p:dataTable id="coloring" var="car" value="#{dataTableController.cars}"
rowStyleClass="#{car.year le 1975 ? 'colored' : null}">
<p:columnheaderText="Year">#{car.year}</p:column>
<p:columnheaderText="Name">#{car.name}</p:column>
</p:dataTable>

The colored style definition could be as simple as the following:

<style type="text/css">
.colored {
background-color: #FF0000;
color: #FFFFFF;
}
</style>

How it works...

With the rowStyleClass attribute, style class can be defined for each row according the manufacturing year ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required