I have a bean that knows what the temperature it is at serveral different locations. That information is displayed in a jsf h:datatable.
<h:dataTable value="#{temperatureBean.records}" var="temperatureRecord" >
<h:column >
<f:facet name="header">Location</f:facet>
#{temperatureRecord.location}
</h:column>
<h:column>
<f:facet name="header">Temperature</f:facet>
#{temperatureRecord.temperature}
</h:column>
</h:dataTable>
I want to give the resulting html <td> elements class values, so that cells for places where the temperature is above zero can, via css, be coloured red, whilst those where the temperature is below zero are coloured blue.
<td class="hot">10</td>
<td class="cold">-2</td>
Could anyone tell me the technique for conditionally generating html <td> attributes?
This question is somewhat similar to a previous answer by BalusC: Dynamically change CSS style of cell in <h:dataTable> column However, in that case, the given solution results in a <span> being generated inside the table cell and it's the class of the span that is programmatically controlled, not any attribute of the <td> element as I'm looking for. The reason that matters is that although I can both give the span a background colour, and tell it to fill the entire width of the table cell, I can't get it to expand to the cell's height.
This fiddle shows the effect of the css given in that previous answer. I've deliberately put something large in the first table cell.
https://jsfiddle.net/twistedlizard/zvLafpsk/
Mojarra: 2.2.0