JSF 2 ui:repeat vs h:datatable行为

问题描述:

我在尝试解决> p:selectBooleanButton不会呈现预选值时遇到了麻烦a>,需要花费大量时间来解决,将ui:repeat更改为h:datatable.

I had a bad time trying to solve p:selectBooleanButton doesn't render preselected value, a lot of hours just to fix it changing ui:repeat to 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)"值)

(Notice that the button is showing 'FALSE (or NO)' value although the property value is 'TRUE' as displayed by outputText)

另一方面,与h:datatable完全相同的代码.

On the other hand, the exactly same code with 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重复标记示例)

Anyone know why is this happening ??. As far as I know, this two tags could be exchangeable. (at least according the example that I saw e.g JSF 2 Repeat Tag Example)

我正在使用com.sun.faces jsf-api和jsf-impl 2.2.4 还有Primefaces 4.0

I'm using com.sun.faces jsf-api and jsf-impl 2.2.4 Also Primefaces 4.0

我有相同的行为,但是无法使用ui和map和默认值正确执行ui:repeat. 在使用素数符号时,您可能还会发现 p:dataGrid 可以替代h:dataTable.

I had the same behavior, and was not able to make work the ui:repeat properly with map and default value. As you are using primefaces, you might also found p:dataGrid as an alternative to h:dataTable.