我需要根据下拉值的选择显示/隐藏tabView中的选项卡。 我编写了一个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>
答案 0 :(得分:0)
您需要在下拉菜单中放置一个<p:ajax event="change" listener="#{bean.onChange}">
,并在bean中创建一个方法,如下所示:(请注意,您还可以将valueChangeListener与ValueChangeEvent一起使用!)
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.
}
祝你好运!