JSF 2 ui:repeat vs h:datatable behavior

荒凉一梦 提交于 2020-01-06 01:34:44

问题


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.

Here is both pieces of code.

 <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>

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

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>

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)

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


回答1:


You confuse view build time with view render time! BalusC posted an explanation here:

JSTL in JSF2 Facelets... makes sense?




回答2:


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.



来源:https://stackoverflow.com/questions/20598827/jsf-2-uirepeat-vs-hdatatable-behavior

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!