O'Reilly logo

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

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. The row styling utilizes the rowStyleClass attribute that has a condition as the EL expression.

In this recipe, we will demonstrate the conditional coloring on rows for countries with GDP (gross domestic product) less than $3,500,000.

How to do it…

A basic definition of a color-coded table that displays a list of countries with their GDPs is given here:

<p:dataTable value="#{dataTableColoringBean.countryGdpList}" var="countryGdp" rowStyleClass="#{countryGdp.gdp le 3500000 ? 'colored' : ''}"> <p:column headerText="Name" sortBy="#{countryGdp.name}"> #{countryGdp.name} </p:column> <p:column headerText="GDP (Millions ...

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