p:selectBooleanButton不呈现预选值

时间:2013-12-13 21:22:06

标签: jsf-2 primefaces

我一直在阅读/尝试几个小时的例子,但我无法让它发挥作用。我正在使用Primefaces 4.0

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

xhtml看起来像这样。

<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,然后分配真值)

 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。

调试时我注意到了一些事情。

  • 正确分配了在Init分配的布尔值。
  • 如果我更改outputLabel的selectBooleanButton,则显示'true'(这是正确的)
  • 当我更改selectBooleanButton并触发事件时,我可以看到HashMap中的'true'值不是java.lang.Boolean而是java.lang.String(attachment)

所以也许,这个问题与演员问题有关,但我在地图中放置了Boolean.TRUE,所以...... 任何想法?

enter image description here

1 个答案:

答案 0 :(得分:-1)

最后我修改了ui:repeat to h:datatable,(我不知道为什么工作)。

我已经创建了另一个问题来请求关于它的一些帮助ui:repeat vs h:datatable behavior

谢谢,