p:selectBooleanButton不呈现预选值 [英] p:selectBooleanButton doesn't render preselected value

查看:68
本文介绍了p:selectBooleanButton不呈现预选值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读/尝试了几个小时的示例,但无法使其正常工作.我正在使用Primefaces 4.0

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

我只需要一种选择/取消选择并将这些值分配给Map的方法

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

xhtml看起来像这样.

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方法(以防万一,将其重置为False,然后分配真值)

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

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

分配TRUE值

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

        }

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

我的预期行为是,当itemsCambiar具有某个项目"TRUE"时,应显示onIcon.但这没有发生,所有p:selectBooleanButton都显示为offIcon.

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.

  • 在Init处分配的布尔值已正确分配.
  • 如果我将outputLabel的selectBooleanButton更改为'true'(正确)
  • 当我更改selectBooleanButton并触发事件时,我可以看到HashMap中的'true'值不是java.lang.Boolean而是java.lang.String(附件)

所以,也许这个问题与转换问题有关,但是我将Boolean.TRUE放置在地图中,所以... 有什么想法吗?

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

推荐答案

最后,我修复了将ui:repeat更改为h:datatable(我不知道为什么会起作用)的问题.

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

我创建了另一个问题,以寻求有关此问题的帮助 ui:repeat vs h:datatable行为

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

谢谢

这篇关于p:selectBooleanButton不呈现预选值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆