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.

4

1 回答 1

8

这个,

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

是不正确的。<p:column><f:facet name="output">支持. 只需将rendered条件放在<h:outputText>自身上。

<p:column>
    <h:outputText value="#{invoice.customerId}" rendered="#{!editUIBean.isEditable('customerId')}" />
    ...
</p:column>
于 2013-05-02T02:01:31.753 回答