2

ユーザーが特定のラジオボタンを選択したときに、非表示のパネルを切り替えたいのですが。Primefacesの最新バージョンを使用します。

例えば:

<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>

このようなことを実現したいのですが、RadioButton3をクリックすると、commandButtonを使用しません

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

それも可能ですか?ありがとう!

4

1 に答える 1

5

次の手順を実行します。

  1. パネルの状態を管理し、それをパネルの属性にbooleanバインドするために、バッキングBeanで変数を宣言します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>
    

    これは、それがselectOneRadiopanel1と同じであることを前提としています。<h:form/>

于 2012-12-11T08:37:07.560 に答える