[英]p:column rendered attribute does not seem to work with p:dataTable var
I have written a code like: 我写了这样的代码:
<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>
But the rendered attribute is not working for the condition. 但是呈现的属性不适用于该条件。 How can I use the logical operator to make the condition work?Using PrimeFaces 3.4.2 如何使用逻辑运算符使条件起作用?使用PrimeFaces 3.4.2
You can't conditionally render a whole column on a per-row basis. 您不能按行有条件地渲染整个列。 This makes logically no utter sense. 从逻辑上讲,这毫无意义。 You can only conditionally render it on a per-table basis. 您只能按表有条件地渲染它。 The <p:column rendered>
cannot take a condition based on properties of the iterated row. <p:column rendered>
不能根据迭代行的属性采取条件。 It can only take a condition based on properties of the parent bean. 它只能采用基于父bean属性的条件。
If you intend to conditionally hide only the cell of the currently iterated row, then just move the rendered
attribute from <p:column>
to <p:commandLink>
or at least a component which wraps the whole <p:column>
content, such as <h:panelGroup>
. 如果您打算有条件地仅隐藏当前迭代行的单元格,则只需将rendered
属性从<p:column>
到<p:commandLink>
或至少一个包裹整个<p:column>
内容的组件,例如为<h:panelGroup>
。
Or if you really intend to conditionally hide a whole column, then move the conditions used in rendered
attribute of <p:column>
to the #{userLeaveBean}
parent bean. 或者,如果您确实打算有条件地隐藏整个列,则将<p:column>
rendered
属性中使用的条件移到#{userLeaveBean}
父bean中。
first import 首次导入
<html xmlns:ui="http://java.sun.com/jsf/facelets">
and add a ui fragment inside the column 并在列内添加一个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>
The best way I used to resolve my problem with the help of GOD BalusC is: 在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>
and it works as smooth as butter! 它像黄油一样光滑!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.