Changing h:datatable cell color or style dynamically in JSF

后端 未结 1 1916
灰色年华
灰色年华 2020-12-11 18:23

I have a datatable where I want to change the color of a cell based on some analysis that is run on the contents. The table is linked to an array of Comment objects, which I

1条回答
  •  北海茫月
    2020-12-11 19:06

    In the standard JSF component, the rowClasses attribute is unfortunately not evaluated on a per-row basis. It's evaluated on a per-table basis. Component libraries like Tomahawk and PrimeFaces however support the kind of attribute which you're looking for on their and .

    With the standard JSF component you need to supply a comma-separated string of all row classes. This can look something like this:

    public String getRowClasses() {
        StringBuilder rowClasses = new StringBuilder();
    
        for (Comment comment : comments) {
            if (rowClasses.length() > 0) rowClasses.append(",");
            rowClasses.append(comment.getCssClass());
        }
    
        return rowClasses.toString();
    }
    

    which is then to be referenced as

    
    

    See also:

    • tag documentation - lists all attributes and the accepted values

    0 讨论(0)
提交回复
热议问题