How can I make p:cellEditor conditional in PrimeFaces?
Asked Answered
D

1

5

Here is my code that doesn't work:

...
<p:column sortBy="#{invoice.customerId}" id="customerId">
    <f:facet name="header"><h:outputText value="Customer ID"/></f:facet>
    <f:facet name="output" rendered="#{!editUIBean.isEditable('customerId')}">
        <h:outputText value="#{invoice.customerId}"/>
    </f:facet>
    <p:cellEditor rendered="#{editUIBean.isEditable('customerId')}">
        <f:facet name="output">
            <h:outputText value="#{invoice.customerId}"/>
        </f:facet>
        <f:facet name="input">
            <h:inputText value="#{invoice.customerId}"/>
        </f:facet>
    </p:cellEditor>
</p:column>
...

So what I am trying to do: The user picks an option, that option determines which records are editable and only displays the records that are editable for that option. For any given option, only certain columns within those records are editable. The isEditable(columnName) method returns true if for given option the column is editable or false if it is not editable. What I want to do is, when the user clicks edit for the record, the editable fields display input fields and then non-editable fields display their values. With the code above, when the column isn't editable, the value doesn't display, before and after clicking edit. When the field is editable, the value displays, and when you click edit, the value is replaced with an input field containing the value. So my example works except that the value is completely hidden when the field is not editable. I want the non-editable values to be displayed when not editing and when editing, I just don't want them to be editable during edit.

Delphadelphi answered 1/5, 2013 at 18:30 Comment(1)
rendered="#{editUIBean.isEditable('customerId')}", how to get 'customerId' ?Hospitium
H
8

This,

<p:column>
    <f:facet name="output" rendered="#{!editUIBean.isEditable('customerId')}">
        <h:outputText value="#{invoice.customerId}" />
    </f:facet>
    ...
</p:column>

is not right. The <p:column> doesn't support a <f:facet name="output">. Just put the rendered condition on the <h:outputText> itself.

<p:column>
    <h:outputText value="#{invoice.customerId}" rendered="#{!editUIBean.isEditable('customerId')}" />
    ...
</p:column>
Hoarfrost answered 2/5, 2013 at 2:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.