根据JSF 2中的条件为数据表的行着色 [英] Color the rows of datatable based a condition in JSF 2

查看:104
本文介绍了根据JSF 2中的条件为数据表的行着色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据条件更改行的背景颜色.

I'd like to change the background color of rows based on a condition.

<t:dataTable id="data"
                styleClass="history-table"
                headerClass="history-table-header"
                rowClasses="history-table-row-default"
                border="2" cellpadding="5" cellspacing="2"
                var="entry"
                value="#{historyBean.logEntryList}"
                preserveDataModel="false"
                rows="#{historyBean.history.rowCount}"
                sortable="true">

           <h:column>
               <f:facet name="header">
                 <h:outputText value="Debug Status" />
               </f:facet>
               <h:outputText value="#{entry.action}" />
           </h:column>

如果"entry.action"的值为XI,则喜欢使用"history-table-row-incomplete"(样式类的名称);如果值为YI,则喜欢使用"history-table-row-error"(样式类的名称).其他所有情况都应使用默认值.

If the value of "entry.action" is X I like to use "history-table-row-incomplete" (name of styleclass), if the value is Y I like to use "history-table-row-error" (name of styleclass). All other cases should use the default value.

我想我必须以某种方式将当前的入口对象获取到我的bean,对其进行分析,然后将一个带有stylclass名称的字符串返回到outputText以更改颜色.但是我不知道如何...(我是JSF的新手...)

I guess i have to get the current object of entry somehow to my bean, analyze it and return a string with the name of the stylclass to outputText to change the color. But I don't know how... (I'm new in JSF...)

有人可以帮我吗?

推荐答案

使用<t:dataTable>rowStyleClass属性而不是rowClasses. rowStyleClass是按行进行评估的,其中var="entry"可用,而rowClasses仅是按表评估的.

Use the rowStyleClass attribute of the <t:dataTable> instead of rowClasses. The rowStyleClass is evaluated on a per-row basis where the var="entry" is available, while the rowClasses is only evaluated on a per-table basis.

<t:dataTable ... rowStyleClass="#{entry.action == 'X' ? 'history-table-row-incomplete' : (entry.action == 'Y' ? 'history-table-row-error' : 'history-table-row-default')}">

这篇关于根据JSF 2中的条件为数据表的行着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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