How to conditionally style a row in a rich:dataTable

后端 未结 7 1565
攒了一身酷
攒了一身酷 2021-02-07 02:12

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

7条回答
  •  萌比男神i
    2021-02-07 02:34

    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:

提交回复
热议问题