p:column rendered attribute does not seem to work with p:dataTable var

后端 未结 3 836
野的像风
野的像风 2020-12-18 10:05

I have written a code like:



        
相关标签:
3条回答
  • 2020-12-18 10:55

    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. It can only take a condition based on properties of the parent 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>.

    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.

    0 讨论(0)
  • 2020-12-18 10:55

    The best way I used to resolve my problem with the help of GOD BalusC is:

    <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!

    0 讨论(0)
  • 2020-12-18 11:00

    first import

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

    and add a ui fragment inside the column

    <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>
    
    0 讨论(0)
提交回复
热议问题