I have a datatable where I want to change the color of a cell based on some analysis that runs in the content. The table is associated with an array of Comment objects, which I provided String cssClass, which is updated after the analysis starts. This is what I tried connecting to the rowClasses property for datatable. It does not work, and I think the problem may be that I cannot access the variable created for each datatable row from inside the datatable declaration.
Valid code:
<h:dataTable value="#{post.comments}" var="comment" class="hs-table" rowClasses="#{comment.cssClass}" >
<h:column>
#{comment.name}
</h:column>
<h:column>
#{comment.email}
</h:column>
<h:column>
#{comment.msg}
</h:column>
</h:dataTable>
Comment class:
public class Comment {
private String msg;
private String email;
private String name;
private Date date;
private String cssClass;
public Comment(){
cssClass = "normColumn";
}
epublic String getCssClass() {
return cssClass;
}
public void setCssClass(String cssClass) {
this.cssClass = cssClass;
}
}
When cssClass is updated in a managed bean:
if(tone>0)
c.setCssClass("commentPos");
else if(tone<0)
c.setCssClass("commentNeg");
A class is never assigned. Am I doing something wrong, or is it just not possible?
source
share