p:列呈现属性似乎不适用于p:dataTable var

时间:2013-06-07 11:12:11

标签: jsf primefaces datatable tablecolumn conditional-rendering

我写了一个代码:

<p:column headerText="Edit" width="40" rendered="#{(leaveDetails.strLeaveStatus == 'Canceled') or (leaveDetails.strLeaveStatus == 'Availed')}">
    <p:commandLink actionListener="#{userLeaveBean.editAppliedLeave}" title="Edit" disabled="true" process="@this" update="leaveDataTable" immediate="false">
        <h:graphicImage url="resources/images/edit.JPG"/>
            <f:attribute name="userId" value="#{employee.name}"/>
            <f:attribute name="editFirstHalf" value="#{leaveDetails.strStartTiming}"/>
            <f:attribute name="editSecondHalf" value="#{leaveDetails.strEndTiming}"/>
            <f:attribute name="editFrom" value="#{leaveDetails.dtLeaveFromDate}"/>
            <f:attribute name="editTo" value="#{leaveDetails.dtLeaveToDate}"/>
            <f:attribute name="leaveId" value="#{leaveDetails.strLeaveId}"/>
    </p:commandLink>
</p:column>

但渲染的属性不适用于该条件。如何使用逻辑运算符使条件有效?使用PrimeFaces 3.4.2

3 个答案:

答案 0 :(得分:10)

您不能在每行的基础上有条件地呈现整个列。这在逻辑上没有任何意义。您只能在每个表的基础上有条件地呈现它。 <p:column rendered>无法根据迭代行的属性采用条件。它只能采用基于父bean属性的条件。

如果您打算有条件地隐藏当前迭代行的单元格,那么只需将rendered属性从<p:column>移动到<p:commandLink>或至少移动一个包裹整个<p:column>的组件。 {1}}内容,例如<h:panelGroup>

或者,如果您确实打算有条件地隐藏整个列,请将rendered <p:column>属性中使用的条件移动到#{userLeaveBean}父bean。

答案 1 :(得分:0)

首次导入

<html xmlns:ui="http://java.sun.com/jsf/facelets">

并在列内添加一个ui片段

<p:column headerText="Edit" width="40">
<ui:fragment rendered="#{(leaveDetails.strLeaveStatus == 'Canceled') or (leaveDetails.strLeaveStatus == 'Availed')}">
    <p:commandLink actionListener="#{userLeaveBean.editAppliedLeave}" title="Edit" disabled="true" process="@this" update="leaveDataTable" immediate="false">
        <h:graphicImage url="resources/images/edit.JPG"/>
            <f:attribute name="userId" value="#{employee.name}"/>
            <f:attribute name="editFirstHalf" value="#{leaveDetails.strStartTiming}"/>
            <f:attribute name="editSecondHalf" value="#{leaveDetails.strEndTiming}"/>
            <f:attribute name="editFrom" value="#{leaveDetails.dtLeaveFromDate}"/>
            <f:attribute name="editTo" value="#{leaveDetails.dtLeaveToDate}"/>
            <f:attribute name="leaveId" value="#{leaveDetails.strLeaveId}"/>
    </p:commandLink>
</ui:fragment> 
</p:column>

答案 2 :(得分:-1)

在GOD BalusC的帮助下,我用来解决问题的最好方法是:

<p:column headerText="Edit" width="40">
    <p:commandLink actionListener="#{userLeaveBean.editAppliedLeave}" title="Edit" process="@this" update="leaveDataTable" 
        immediate="false" disabled="#{(leaveDetails.strLeaveStatus == 'Canceled') or (leaveDetails.strLeaveStatus == 'Availed')}">
        <h:graphicImage url="resources/images/edit.JPG"/>
        <f:attribute name="userId" value="#{employee.name}"/>
        <f:attribute name="editFirstHalf" value="#{leaveDetails.strStartTiming}"/>
        <f:attribute name="editSecondHalf" value="#{leaveDetails.strEndTiming}"/>
        <f:attribute name="editFrom" value="#{leaveDetails.dtLeaveFromDate}"/>
        <f:attribute name="editTo" value="#{leaveDetails.dtLeaveToDate}"/>
        <f:attribute name="leaveId" value="#{leaveDetails.strLeaveId}"/>
    </p:commandLink>
</p:column>

它和黄油一样顺畅!