I am creating a table with p: dataTable (PrimeFaces), and what I want to do is the background color of the cells depending on the value of their contents. This is different from coloring a row or column - it is a separate cell.
The CSS problem first. If I do this:
<p:column headerText="xyzzy"> <div style="background-color: green"> <h:outputText value="#{rowVar.anumber}" > <f:convertNumber groupingUsed="true" /> </h:outputText> </div> </p:column>
the background color of only the content is set, not the whole cell. In other words, padding is still the default.
Secondly, I want the style string to be a variable expression. I can add a function to bean support, but how do I access the contents of a table in a method? Will this work?
<div style="#{bean.computeCSS(rowVar.number}">
EDIT:
I figured out a way to make the conditional part, but I still need help with the CSS part. My solution looks like this:
<p:column headerText="xyzzy"> <div class="#{rowVar.anumber gt 0 ? 'colored' : ''}"> <h:outputText value="#{rowVar.anumber}"> <f:convertNumber groupingUsed="true" /> </h:outputText> </div> </p:column>
Although I donβt like to be interested in EL, it has the advantage of not needing a bean support method.
However, I still get only the background color, not the whole cell.
source share