如何使用p:selectBooleanCheckbox切换禁用/启用PrimeFaces组件

时间:2015-04-27 13:18:13

标签: jsf primefaces

是否有一些简单的方法可以根据selectBooleanCheckbox在selectOneMenu上切换禁用/启用

<p:selectBooleanCheckbox label="labelBox" onchange="(PF('SelectList').enable();" />
<p:selectOneMenu id="listUrgent" value="#{projectsControllerCreate.selected.listUrgent}" widgetVar="SelectList" > 

1 个答案:

答案 0 :(得分:1)

在bean中定义一个布尔值并将其绑定到p:selectBooleanCheckbox。然后,设置ajax侦听器,以便根据该值更新p:selectOneMenu状态。

<强> XHTML

<p:selectBooleanCheckbox label="labelBox" value="#{projectsControllerCreate.selectionAllowed}">
     <p:ajax event="change" update="listUrgent" />
</p:selectBooleanCheckbox>
<p:selectOneMenu id="listUrgent" value="#{projectsControllerCreate.selected.listUrgent}" disabled="#{!projectsControllerCreate.selectionAllowed}">
      ...
</p:selectOneMenu>

bean(projectsControllerCreate)

private boolean selectionAllowed;

public boolean isSelectionAllowed() {
     return selectionAllowed;
}

public void setSelectionAllowed(boolean selectionAllowed) {
     this.selectionAllowed = selectionAllowed;
}