0
votes

I am using an h:datatable which shows a summary of the data entered by a user in a session. The rows of the table are deletable at the users discretion. if the data meets certain criterion, the specific row in the table must be in red font color, else it should be black.

The methods I have tried so far are: - Set the style value for h:outputtext component in each column value to red programmatically. But this changes entire columns color. - Set the rowclasses programmatically, this again changes the style for all previous rows.

I am unable to target just one row or cell. I thought about using javascript, but without the id of the component I am not sure how to get the element.

Thanks.

2

2 Answers

2
votes

Use the rowClasses attribute.

<h:dataTable value="#{bean.items}" var="item" rowClasses="#{bean.rowClasses}">

The getRowClasses() must return a comma separated string of CSS class names which are to be applied on rows (more specifically, the <tr> elements) repeatedly. You can create it based on the items inside bean's (post)constructor, action methods and/or even inside the getter.

0
votes

For some reason, the StringBuffer was being overwritten thats the reason the change wasn't showing. I went with a simpler approach of adding an alert img to the rows that needed to be modified.