2011-12-21 17 views
3

私はPrimefaces 2.2を使用しています。私はそれの中に3つのタブを持つp:tabViewを持っています。 Tab1にはブールチェックボックスがあります。今、私はそれがタブ1のチェックボックスをクリックすると、タブ2が無効になりたいと思う。どうすればいいですか?ここにコードのプレビューがあります。チェックボックスの選択でPrimeFacesタブを無効にする方法

<h:body> 

    <p:panel header="F.C. Barcelona" footer="Visca el Barca!"> 

     <p:tabView> 

      <p:tab id="tab1" title="Godfather Part I"> 
       <h:panelGrid columns="2" cellpadding="10"> 
        <h:outputText value="In tab1." /> 
       </h:panelGrid> 

       <h:selectBooleanCheckbox id="Mark" 
             value="#{disableTag.disable}" > 
        <f:ajax render="tab2" /> 
       </h:selectBooleanCheckbox> 

      </p:tab> 

      <p:tab id="tab2" title="Godfather Part II"> 
       <h:panelGrid columns="2" cellpadding="10"> 

        <h:outputText value="In tab2." /> 
       </h:panelGrid> 
      </p:tab> 

      <p:tab id="tab3" title="Godfather Part III"> 
       <h:panelGrid columns="2" cellpadding="10"> 

        <h:outputText value="In tab3." /> 
       </h:panelGrid> 
      </p:tab> 

     </p:tabView> 

    </p:panel> 

</h:body> 

おかげ

答えて

1
<h:form id="myFormId">  
    <p:panel header="F.C. Barcelona" footer="Visca el Barca!"> 

     <p:tabView> 

      <p:tab id="tab1" title="Godfather Part I" disabled="#{myBean.myBooleanFirstTabDisable}"> 
       <h:panelGrid columns="2" cellpadding="10"> 
        <h:outputText value="In tab1." /> 
       </h:panelGrid> 

       <h:selectBooleanCheckbox id="Mark" 
             value="#{disableTag.disable}" > 
        <p:ajax event="check" update="myFormId" listener="#{myBean.myMethodEvaluatingDisabledTabs}" /> 
       </h:selectBooleanCheckbox> 

      </p:tab> 

      <p:tab id="tab2" title="Godfather Part II" disabled="#{myBean.myBooleanSecondTabDisable}"> 
       <h:panelGrid columns="2" cellpadding="10"> 

        <h:outputText value="In tab2." /> 
       </h:panelGrid> 
      </p:tab> 

      <p:tab id="tab3" title="Godfather Part III" disabled="#{myBean.myBooleanThirdTabDisable}"> 
       <h:panelGrid columns="2" cellpadding="10"> 

        <h:outputText value="In tab3." /> 
       </h:panelGrid> 
      </p:tab> 

     </p:tabView> 

    </p:panel> 
</h:form> 

は、だから、フォームコンポーネントを持っている必要があり、あなたがprimefacesアヤックスとupdate属性を使用することができます見ることができるように...方法/リスナーmyMethodEvaluatingDisabledTabsはブール値を変更するために使用されます値はdisabledの各タブで使用されます。したがって、必要なタブごとにdisabled=trueに変更します(この場合は3つのブール変数があります)。フォーム全体を更新します。

PS:私は、Ajaxのイベントについて確認する必要が....

+0

私はPrimeFaces 2.2を使用しています。 p:tabにdisable属性はありません。 – Basit

+0

@Basit aaa ...あなたが正しいです、私は忘れました! – spauny

+0

@Basitそれでは、それらを無効にすることはできません...レンダリングをfalseに設定するだけで、表示しないことができます – spauny

1

ここで私はそれをやりました。

<h:head> 
    <title>Facelet Title</title> 
</h:head> 
<h:body> 
    <h:form> 

     <p:panel id="myPanel" header="F.C. Barcelona" footer="Visca el Barca!"> 

      <p:tabView id="myTabView" tabChangeListener="#{disableTag.onChange}" > 

       <p:tab id="tab1" title="Godfather Part I"> 
        <h:panelGrid columns="2" cellpadding="10"> 
         <p:panel header="Basit" footer="Basit"> 


         </p:panel> 
         <h:outputText value="In tab1." /> 
        </h:panelGrid> 

        <h:outputText value="Click to hideGodfather Part II " /> 
        <h:selectBooleanCheckbox id="Mark" 
              value="#{disableTag.disable}" 
              valueChangeListener="#{disableTag.changeMark}"> 
         <f:ajax render="@this myTabView" /> 
        </h:selectBooleanCheckbox> 

       </p:tab> 

       <p:tab id="tab2" 
         title="Godfather Part II" 
         rendered="#{disableTag.rendered}"> 
        <h:panelGrid columns="2" cellpadding="10"> 

         <h:outputText value="In tab2." /> 
        </h:panelGrid> 
       </p:tab> 

       <p:tab id="tab3" title="Godfather Part III"> 
        <h:panelGrid columns="2" cellpadding="10"> 

         <h:outputText value="In tab3." /> 
        </h:panelGrid> 
       </p:tab> 

      </p:tabView> 

     </p:panel> 

    </h:form> 

</h:body> 

@ManagedBean 
@ViewScoped 
public class DisableTag implements Serializable { 

    private boolean disable; 
    private boolean rendered; 

    /** Creates a new instance of DisableTag */ 
    public DisableTag() { 

     rendered = false; 

    } //end of constructor 

    public boolean isDisable() { 
     return disable; 
    } 

    public void setDisable(boolean disable) { 
     this.disable = disable; 
    } 

    public boolean isRendered() { 
     return rendered; 
    } 

    public void setRendered(boolean rendered) { 
     this.rendered = rendered; 
    } 

    public void changeMark(ValueChangeEvent vcEvent){ 

     rendered = Boolean.valueOf(vcEvent.getNewValue().toString()).booleanValue(); 
     System.out.println(); 

    } 

} //end of class DisableTag 
関連する問題