JSF rowStyleClass how to get the current date


I am working with JSF and Primefaces. I want to show some rows of a datatable with a different background color depending on a condition. That condition is if a date () is greater or equal than current date that rows must be shown with a color especified in the CSS file. How can I get the current date?

This is the Facelet

<p:dataTable id="dataTableCitizens" rowStyleClass="#{item.dateLastDate ge currentDate ? 'colored' : null}" value="#{citizensManagedBean.listCitizens}"  var="item">

This is the CSS

.colored {
background-color: yellow;

I have created a faces-config.xml file inside WEB-INF with the following code:

<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.0"
              xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">


, but when I run the web app it gives me a java.lang.NullPointerException. What am I doing wrong?

The most basic solution is to create a variable in your bean and initiate it with a @PostConstruct annotation :

private Date currentDate;

public void init() {
     currentDate = new Date();

//Getter and Setters...

Then you can access it in your view : #{yourBean.currentDate}

Or you can use Omnifaces' default implementation of #{now}.