How to conditionally style a row in a rich:dataTab

2020-05-30 08:49发布

How can I change the style of a particular row based on a condition? I can use JSF EL in rich:column style class attribute, but I have to write for each column. I want to change the entire row.

Thanks

7条回答
ら.Afraid
2楼-- · 2020-05-30 09:47

When using h:datatable, create a bean method and call this to determine the style. Perhaps this could also be done for a rich:datatable?

    public String getStyleSelectedOrderRows() {
        StringBuilder sb = new StringBuilder();
        String[] oddEven = new String[]{"oddRow,", "evenRow,"};
        int i = 0;
        for (MyObject object: myObjectList) {
            sb.append(object.isSelected() ? "selected," : oddEven[i++ % 2]);
        }
        return sb.toString();
    }

and in the .xhtml:

<h:dataTable rowClasses="#{bean.styleSelectedOrderRows}"

查看更多
登录 后发表回答