p:selectBooleanButton doesn't render preselected value

天大地大妈咪最大 提交于 2019-12-24 16:38:57

问题


I been reading / trying examples for hours, and I can't make it work. I'm using Primefaces 4.0

I just need a way to select/unselect and assign those values to a Map

The xhtml looks like this.

<p:selectBooleanButton value="#{presupuestoBean.itemsCambiar[itemPresupuesto.id]}"
onLabel="Yes" offLabel="No" onIcon="ui-icon-check" offIcon="ui-icon-close">
     <p:ajax listener="#{presupuestoBean.updateItemPresupuestoAsignado(itemPresupuesto.id,0)}"/>
</p:selectBooleanButton>

Init Method (reset to False just in case, and then assign the true values)

 for (ItemPresupuesto itemsPresupuestoDefault : itemsPresupuestoDefaults) {
        itemsCambiar.put(itemsPresupuestoDefault.getId(),Boolean.FALSE);
    }

assign TRUE values

if (itemPresupuestoAsignado.isCambiar()) {
            itemsCambiar.put(itemPresupuestoAsignado.getId(), Boolean.TRUE);

        }

and

public Map<Long, Boolean> getItemsCambiar() {
        return itemsCambiar;
    }

My expected behavior is when the itemsCambiar has some item 'TRUE', the onIcon should be displayed. But it's not happening, all p:selectBooleanButton are displaying as offIcon.

I notice a couple of things while debugging.

  • The Boolean value assigned at Init, is properly assigned.
  • If I change the selectBooleanButton for an outputLabel, is showing 'true' (which is correct)
  • When I change the selectBooleanButton, and the event is fired, I can see that the 'true' value in the HashMap is not a java.lang.Boolean but a java.lang.String (attachment)

So maybe, this problem is related a cast problem, but I'm putting Boolean.TRUE in the map, so ... any ideas?


回答1:


Finally I fixed changing ui:repeat to h:datatable, (I don't know why is working).

I have created another question to request some help about it ui:repeat vs h:datatable behavior

Thanks,



来源:https://stackoverflow.com/questions/20576218/pselectbooleanbutton-doesnt-render-preselected-value

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