Javascript 在primefaces中显示/隐藏选项卡

Javascript 在primefaces中显示/隐藏选项卡,javascript,primefaces,Javascript,Primefaces,我需要根据下拉值的选择在选项卡视图中显示/隐藏选项卡。 我已经编写了一个javaScript函数,其中我必须编写一个逻辑来显示/隐藏这个选项卡。 我无法使用选项卡的id获取客户端id。 有没有办法在不使用呈现条件的情况下用javascript隐藏/显示选项卡 代码段: <p:tabView orientation="left" widgetVar="table" id="tabId"> <p:tab title="Godfather Part I" id="ta

我需要根据下拉值的选择在选项卡视图中显示/隐藏选项卡。 我已经编写了一个javaScript函数,其中我必须编写一个逻辑来显示/隐藏这个选项卡。 我无法使用选项卡的id获取客户端id。 有没有办法在不使用呈现条件的情况下用javascript隐藏/显示选项卡

代码段:

    <p:tabView orientation="left" widgetVar="table" id="tabId">
    <p:tab title="Godfather Part I" id="tab1">
        <h:panelGrid columns="2" cellpadding="10">
           <h:outputText
                value="The story begins as Don Vito Corleone..." />
        </h:panelGrid>
    </p:tab>
    <p:tab title="Godfather Part II" id="tab2">
        <h:panelGrid columns="2" cellpadding="10">
           <h:outputText value="Francis Ford Coppola's legendary..." />
        </h:panelGrid>
    </p:tab>
    <p:tab title="Godfather Part III" id="tab3">
        <h:panelGrid columns="2" cellpadding="10">
         <h:outputText value="After a break of more than 15 years..." />
        </h:panelGrid>
    </p:tab>
</p:tabView>

您需要在下拉菜单中放置一个
,并在bean中创建一个方法,如下所示:(请注意,您还可以将valueChangeListener与ValueChangeEvent一起使用!)

祝你好运

OP说:“我需要显示/隐藏一个选项卡…”。建议的解决方案仅选择特定选项卡;它不会切换选项卡的可见性。
public void onChange(AjaxBehaviorEvent event){
  /* get the value from the dropdown into a variable, supposing the dropdown
     contains Integers with possible tab indexes, or contains objects
     with these indexes as attributes.
  */  
  String tabIndex = (String) ((UIOutput)event.getSource()).getValue();
  ...
  RequestContext.getCurrentInstance().execute("PF('table').select(" + tabIndex + ");");
  //in this case, table is the widgetVar of your tabView.
}