【发布时间】:2014-01-03 03:07:06
【问题描述】:
我在尝试解决 p:selectBooleanButton doesn't render preselected value 时遇到了麻烦,我花了很多时间来修复它,将 ui:repeat 更改为 h:datatable。
这是两段代码。
<ui:repeat value="#{presupuestoBean.getItemsPresupuestBySeccion('Parte Delantera')}" var="itemPresupuesto">
<tr>
<td><h:outputText value="#{itemPresupuesto.descripcion}"/></td>
<td>
<p:selectBooleanButton value="#{presupuestoBean.itemsPresupuestoAsignadoCambiar[itemPresupuesto.id]}" onLabel="Yes" offLabel="No" onIcon="ui-icon-check" offIcon="ui-icon-close"/>
<h:outputText value="#{presupuestoBean.itemsPresupuestoAsignadoCambiar[itemPresupuesto.id]}" />
</td>
</tr>
</ui:repeat>
(请注意,尽管 outputText 显示的属性值为“TRUE”,但按钮显示的是“FALSE(或 NO)”值)
另一方面,与 h:datatable 完全相同的代码。
<h:dataTable value="#{presupuestoBean.getItemsPresupuestBySeccion('Parte Delantera')}" var="itemPresupuesto2">
<h:column>
<h:outputText value="#{itemPresupuesto2.descripcion}"/>
</h:column>
<h:column>
<p:selectBooleanButton value="#{presupuestoBean.itemsPresupuestoAsignadoCambiar[itemPresupuesto2.id]}" onLabel="Si" offLabel="No" onIcon="ui-icon-check" offIcon="ui-icon-close"/>
<h:outputText value="#{presupuestoBean.itemsPresupuestoAsignadoCambiar[itemPresupuesto2.id]}" />
</h:column>
</h:dataTable>
有人知道为什么会这样吗???。据我所知,这两个标签可以互换。 (至少根据我看到的例子,例如JSF 2 Repeat Tag Example)
我正在使用 com.sun.faces jsf-api 和 jsf-impl 2.2.4 还有 Primefaces 4.0
【问题讨论】:
-
#presupuestoBean.itemsPresupuestoAsignadoCambiar[itemPresupuesto.id]}}语法无效,是否只是复制错误? -
@AlexandreLavoie,是的。只是复制错误。谢谢! (我已经编辑了我的答案)
-
那么再次确认
{在#之后丢失。 -
您没有告诉我们您的 jsf-primefaces 版本。除此之外,您应该提供一个SSCCE 以使您的代码可以复制粘贴和运行。
-
@AlexandreLavoie 谢谢!我修复了代码。我在尝试将代码复制粘贴到 stackoverflow 编辑器时遇到问题。
标签: jsf-2