如何获得在阿贾克斯监听SelectBooleanCheckbox的状态呢? [英] How to get state of SelectBooleanCheckbox in Ajax Listener?

查看:208
本文介绍了如何获得在阿贾克斯监听SelectBooleanCheckbox的状态呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的基础上的复选框的状态在ManagedBean一些行动。

I'm trying to do some action in the ManagedBean based on the state of the checkbox.

复选框是在这里:

<p:selectBooleanCheckbox id="cb">
    <p:ajax listener="#{myBB.checkboxChanged}"/>
</p:selectBooleanCheckbox>

监听方法的签名是这样的:

The signature of the listener method is this:

public void checkboxChanged(AjaxBehaviorEvent event)

监听器方法被称为预期,但我不知道如何得到复选框的状态(如果它被选中) 这是错误的所有的时间:

The listener method is called as expected, but I'm not sure how to get the state of the checkbox(if it is selected) This is false all the time:

((SelectBooleanCheckbox)event.getSource()).isSelected()

我需要绑定的复选框的值?我想避免这种情况,因为从枚举在一个循环中产生的复选框,我不从哪里绑定(模型设计在我加入的方式/删除枚举的例子有任何布尔集合,不设置布尔值属性)

Do I need to bind the value of the checkbox? I'd like to avoid that, because the checkboxes are generated from enum in a loop and I don't have any boolean where to bind it(the model is designed in a way that I'm adding/removing the instances of enum to a collection, not setting boolean properties)

我跑在Tomcat 6.0.36的code与Primefaces 3.5

I'm running the code on Tomcat 6.0.36 with Primefaces 3.5

JSF实现就是Apache MyFaces的2.1.10

JSF implementation is Apache Myfaces 2.1.10

推荐答案

您code按预期工作,我对Mojarra 2.2.1和PrimeFaces 4.0RC1以及Mojarra 2.0.3和PrimeFaces 3.5。不幸的是,我没有2.1得心应手。您使用的是什么版本的PrimeFaces的?您可以发布您完成code?

Your code works as expected for me on Mojarra 2.2.1 and PrimeFaces 4.0RC1 as well as Mojarra 2.0.3 and PrimeFaces 3.5. Unfortunately I didn't have 2.1 handy. What version of PrimeFaces are you using? Can you post your complete code?

这篇关于如何获得在阿贾克斯监听SelectBooleanCheckbox的状态呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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