Primefaces数据表:从bean设置行颜色 [英] Primefaces datatable: set row color from bean

查看:63
本文介绍了Primefaces数据表:从bean设置行颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题可能在第一次出现时就是重复的,但是我没有找到其他人遇到相同的问题.

This question might appear as duplicate at the first time, but I didn't find someone else with the same problem.

我们要在数据表中设置特定的行颜色.我们发现只有一种漂亮"的方法可以做到:使用 rowStyleClass 属性,该属性将应用 CSS 文件中定义的类中的样式.

We want to set specific row color in datatable. We found that there is only one "pretty" way to do it: using rowStyleClass attribute, which will apply styles from classes defined in CSS file.

但是在我们的情况下,颜色是从外部数据库视图获得的,可以随时更改.这意味着我们无法在 CSS 文件中定义固定样式.

But in our case, colors are obtained from the external database view and can be changed any time. It means that we can't define fixed styles in CSS file.

不幸的是,没有 rowStyle 属性.关于如何根据bean十六进制值生成的行颜色设置任何建议?

Unfortunately, there is no rowStyle attribute. Any suggestions of how we can set row colors based on generated by bean hexadecimal value?

(我们正在使用PF 5.3)

(we are using PF 5.3)

推荐答案

您不能使用 rowStyle .但是,您可以通过编程方式更改 styleClass css .从支持bean中获得 css 样式.

You cannot use rowStyle. But, you can change css of thestyleClass programmatically. Get css style from your backing bean.

请勿在css文件中放置以下 style .只需将其放入显示 datatable jsf 页面即可.

Don't put the following style in css file. Just put it into your jsf page which show the datatable.

<style>
    .oddRowStyle {
        #{MyBean.oddRowStyle}
    }
    .evenRowStyle {
        #{MyBean.evenRowStyle}
    }
</style>
<p:dataTable .....  rowIndexVar="index" 
    rowStyleClass="#{(index mod 2) eq 0 ? 'evenRowStyle' : 'oddRowStyle'}"/>

MyBean.java

MyBean.java

public String getOddRowStyle() {
    /*Change Your style as programmatically*/
    return "background-color: #F7F7F7!important ;";
}

public String getEvenRowStyle() {
    /*Change Your style as programmatically*/
    return "background-color: #05855F!important ;";
}

这篇关于Primefaces数据表:从bean设置行颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆