Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make p:cellEditor conditional in PrimeFaces?

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.

like image 902
Roberto Murphy Avatar asked May 01 '13 18:05

Roberto Murphy


1 Answers

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>
like image 53
BalusC Avatar answered Oct 22 '22 20:10

BalusC