1
votes

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>

UI repeat output

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

Datatable Ouput

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

2
#presupuestoBean.itemsPresupuestoAsignadoCambiar[itemPresupuesto.id]}} is invalid syntax, is it only a copy mistake?Alexandre Lavoie
@AlexandreLavoie, yes. Was just a copy mistake. Thanks! (I've edited my answer)psabbate
Well verify again there are { missing right after #.Alexandre Lavoie
You don't tell us your jsf-primefaces versions. Apart from that, you should provide an SSCCE to make your code copy-paste and runnable.Xtreme Biker
@AlexandreLavoie thanks! I fixed the code. I had problems trying to copy paste the code into the stackoverflow editor.psabbate

2 Answers

1
votes

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

JSTL in JSF2 Facelets... makes sense?

1
votes

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.