2011-12-21 170 views
3

我正在使用Primefaces 2.2。我有p:tabView裏面有三個選項卡。 Tab1包含一個布爾值複選框。現在我想要當用戶點擊tab1中的複選框時,然後選項卡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> 

所以,你必須有一個表單組件,正如你可以看到你可以用......的方法/監聽myMethodEvaluatingDisabledTabs用於改變布爾primefaces Ajax和更新屬性值在每個選項卡中使用disabled屬性:因此,您需要爲每個選項卡更改爲disabled=true(在這種情況下,您將有3個布爾變量),然後更新整個表單。

PS:我要檢查有關AJAX事件....

+0

我正在使用PrimeFaces 2.2。 p:中沒有禁用屬性 – Basit 2011-12-21 11:15:31

+0

@Basit aaa ...你是對的,我忘了! – spauny 2011-12-21 11:20:51

+0

@Basit所以你不能禁用它們......你只能將渲染設置爲false,而不會顯示它們 – spauny 2011-12-21 11:21:59

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 
相關問題