Primefaces数据表中的样式ENUM

时间:2013-03-22 14:54:50

标签: java jsf primefaces

我正在尝试使用dataTable的rowStyleClass属性将行的颜色设置为红色。条件是比较枚举,所以如果invoice.status eq InvoiceStatus.CANCELLED,那么它应该将css类'cancelled'应用于该行。我认为这可能不是比较枚举与EL 的正确方法。你能告诉我怎么做吗?


              

        <p:dataTable id="invoicesTable" widgetVar="invoicesTable" 
                                        value="#{invoiceManager.invoices}"
                                        var="invoice" 
                                        filteredValue = #{invoiceManager.filteredInvoices}"
                                        paginator="true" 
                                        rows="15" 
                                        paginatorPosition="bottom"
                                        paginatorAlwaysVisible="false"
                                        emptyMessage="#{msg['warning.noData']}"
           HERE's THE PROBLEM  -->      rowStyleClass="#{invoice.status eq CANCELLED ? 'cancelled' : null}">
            <f:facet name="header">
                <h:outputText value="#{msg['title.invoices']}" />
                <p:outputPanel style="position: relative; left: 42%;">
                    <h:inputText id="globalFilter" onkeyup="invoicesTable.filter()" />
                </p:outputPanel>                
            </f:facet>

            <p:column headerText="#{msg['label.number']}" filterBy="#{invoice.number}" filterStyle="display: none;">
                <h:outputText value="#{invoice.number}" />
            </p:column>

            <p:column headerText="#{msg['label.customerName']}">
                <h:outputText value="#{invoice.customer.name}" />
            </p:column>

            <p:column headerText="#{msg['label.action']}" styleClass="actionsColumn">
                <p:commandButton process="@this" action="confirmInvoice" icon="ui-icon-search" title="#{msg['button.viewInvoice']}" >
                    <f:setPropertyActionListener target="#{invoiceManager.invoice}" value="#{invoice}" />
                </p:commandButton>
                <p:commandButton process="@this" action="#{invoiceManager.changeInvoiceStatus}" icon="ui-icon-flag" title="#{msg['button.changeInvoiceStatus']}" >
                    <f:setPropertyActionListener target="#{invoiceManager.invoice}" value="#{invoice}" />
                </p:commandButton>
            </p:column>
        </p:dataTable>

1 个答案:

答案 0 :(得分:3)

EL中的枚举被解释为字符串。你需要引用枚举值。

rowStyleClass="#{invoice.status eq 'CANCELLED' ? 'cancelled' : null}"

或者,您可以向枚举添加新方法

public String getStyleClass() {
    return name().toLowerCase();
}

并按如下方式使用

rowStyleClass="#{invoice.status.styleClass}"