Primefaces selectOneButton:通过JS/jquery设置选定的选项

Seb*_* S. 2 jquery jsf client-side primefaces

是否可以在客户端更改JSF selectOneButton组件的选定项?Primefaces是否已经提供了一种方便的方法来执行此操作?

在组件上设置'widgetVar'属性时,相应的JS对象有一个方法'select(a)',它似乎停用以前激活的按钮,然后激活参数'a'给出的新按钮:

select: function(a)
{
    this.buttons.filter(".ui-state-active").removeClass("ui-state-active ui-state-hover").children(":radio").removeAttr("checked");
    a.addClass("ui-state-active").children(":radio").attr("checked", "checked").change()
}
Run Code Online (Sandbox Code Playgroud)

但我不知道该怎么设置参数'a'.这是正确的方法吗?

Bal*_*usC 6

您需要传递表示具体的jQuery对象,该对象表示<div>UI中的所需按钮.它们都可以通过buttonswidget var 的属性获得,它返回一个数组.

因此,如果您需要选择第3个按钮,那么此示例应该执行此操作,前提是窗口小部件名称为foo:

foo.select($(foo.buttons[2]));
Run Code Online (Sandbox Code Playgroud)

请注意,这似乎是一个内部方法(使用模块模式未隐藏)并且未在"用户指南"中记录,因此在未来的PF版本中,它将受到未记录的更改.