This is the Java code
@ManagedBean
public class DatatableBean {
private List<Employee> emplList = new ArrayList<Employee>();
public DatatableBean(){
emplList.add(new Employee("Jack", 1, "Engineer"));
emplList.add(new Employee("Jim", 2, "Engineer"));
emplList.add(new Employee("Kelly", 3, "Manager"));
}
public List<Employee> getEmplList() {
return emplList;
}
public void setEmplList(List<Employee> emplList) {
this.emplList = emplList;
}
}
This is the XHTML code
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head><title>JSF datatable demo</title>
<style>
.employee {
font: verdana;
background:green;
}
.manager {
font: arial;
background:blue;
}
.default {
font: helvetica;
background:red;
}
</style>
</h:head>
<body>
<h:dataTable rowClasses="#{empl.designation eq 'Manager' ? 'manager' : empl.designation eq 'Engineer' ? 'employee' : 'default'}"
<h:column>
<f:facet name="header">
<h:outputText value="Id" />
</f:facet>
<h:outputText value="#{empl.id}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Name" />
</f:facet>
<h:outputText value="#{empl.name}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Designation" />
</f:facet>
<h:outputText value="#{empl.designation}" />
</h:column>
</h:dataTable>
</body>
</html>
I followed this answer
Color the rows of datatable based a condition in JSF 2
and wrote the above code. But only the default css is rendered in the browser for all rows.
Even if I change 'eq' to '==', the output remains the same.
This is the code rendered in the browser
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>JSF datatable demo</title>
<style>
.employee {
font: verdana;
background:green;
}
.manager {
font: arial;
background:blue;
}
.default {
font: helvetica;
background:red;
}
</style></head>
<body><table>
<thead>
<tr>
<th scope="col">Id</th>
<th scope="col">Name</th>
<th scope="col">Designation</th>
</tr>
</thead>
<tbody>
<tr class="default">
<td>1</td>
<td>Jack</td>
<td>Engineer</td>
</tr>
<tr class="default">
<td>2</td>
<td>Jim</td>
<td>Engineer</td>
</tr>
<tr class="default">
<td>3</td>
<td>Kelly</td>
<td>Manager</td>
</tr>
</tbody>
</table>
</body>
</html>
Please help
Thanks in advance