5

我写了如下代码:

<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

4

3 回答 3

12

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

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

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

于 2013-06-07T11:18:14.800 回答
-1

首次进口

<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>
于 2018-11-19T18:28:04.500 回答
-2

我过去在 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>

它像黄油一样光滑!

于 2013-06-07T11:56:42.723 回答