切换<p:panel>,具体取决于所选值<p:selectOneRadio>



我想在用户选择特定单选按钮时切换隐藏面板。使用最新版本的素数。

例如:

<p:panel id="panel1" visible="false" widgetVar="firePanel" closable="true" toggleable="true">
 hello
</p:panel>
<p:selectOneRadio value="#{formBean.selectedOptions}" layout="pageDirection">
  <f:selectItem itemLabel="Option 1" itemValue="opt1" />
  <f:selectItem itemLabel="Option 2" itemValue="opt2" />
  <f:selectItem itemLabel="Option 3" itemValue="opt"/>                           
</p:selectOneRadio>

我想实现这样的事情,但是当单击单选按钮3时,不使用命令按钮

<p:commandButton id="but" value="Show" onclick="firePanel.show();"/>

这可能吗?谢谢!

执行以下步骤:

  1. 在后备 Bean 中声明一个 boolean 变量来管理面板的状态,并将其绑定到面板的 visible 属性

    boolean panelIsVisible;
    //getter and setter
    
    <p:panel id="panel1" visible="#{formBean.panelIsVisible}" widgetVar="firePanel" closable="true" toggleable="true">
    
  2. 定义一个方法,以根据 selectedOptions 的值切换可见性布尔值

    public void changePanelState(){
        //set panelIsVisible to true or false based on whatever conditions you choose
    }
    
  3. <p:ajax/>事件添加到<p:selectOneRadio/>,以在该菜单上的任何选择上触发 ajax 事件

    <p:selectOneRadio value="#{formBean.selectedOptions}" layout="pageDirection">
      <f:selectItem itemLabel="Option 1" itemValue="opt1" />
      <f:selectItem itemLabel="Option 2" itemValue="opt2" />
      <f:selectItem itemLabel="Option 3" itemValue="opt"/> 
      <p:ajax listener="#{formBean.changePanelState}" update="panel1"/>                          
    </p:selectOneRadio>
    

    这是假设panel1与selectOneRadio处于同一<h:form/>

最新更新