这是我的代码不起作用:
...
<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>
...
所以我想要做的是:用户选择一个选项,该选项确定哪些记录是可编辑的,并且只显示该选项可编辑的记录。对于任何给定的选项,只有这些记录中的某些列是可编辑的。如果对于给定的选项列是可编辑的,则 isEditable(columnName) 方法返回 true,如果它不可编辑,则返回 false。我想要做的是,当用户单击记录的编辑时,可编辑字段显示输入字段,然后不可编辑字段显示其值。使用上面的代码,当该列不可编辑时,在单击编辑之前和之后都不会显示该值。当该字段可编辑时,会显示该值,当您单击“编辑”时,该值将替换为包含该值的输入字段。所以我的示例有效,只是当该字段不可编辑时该值完全隐藏。我希望在不编辑和编辑时显示不可编辑的值,我只是不希望它们在编辑期间可编辑。
最佳答案
这个,
<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>
关于jsf - 我怎样才能使 p :cellEditor conditional in PrimeFaces?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16324097/