Java 如何在 Primefaces tabView 中设置活动选项卡?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6514352/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do i set the active tab in Primefaces tabView?
提问by Horacio González
I have a menubar in which two items on a submenu, both calling the same page:
我有一个菜单栏,其中子菜单上的两个项目都调用同一个页面:
<p:menubar autoSubmenuDisplay="true">
<p:submenu label="Perfil">
<p:menuitem value="Editar" url="perfil.xhtml" />
<p:menuitem value="Ver" url="perfil.xhtml" />
</p:submenu>
</p:menubar>
In that page i have a tabview with two tabs:
在该页面中,我有一个带有两个选项卡的 tabview:
<p:tabView dynamic="true">
<p:tab id="ver" title="Ver perfil">
<ui:include src="verPerfil.xhtml" />
</p:tab>
<p:tab id="editar" title="Editar perfil">
<ui:include src="editarPerfil.xhtml" />
</p:tab>
</p:tabView>
How can i set the active tab, so each menuitem activate the corresponding tab?
如何设置活动选项卡,以便每个菜单项激活相应的选项卡?
采纳答案by FishGel
If you want to do this.You can't use the url
in the p:menuitem
because we must call a method to changing the tabindex beforeskipping to the prefil.xhtml
page. If you use the url
, the method will be invoked after we skip to the prefil.xhtml
page .
如果你想这样做。你不能使用url
in ,p:menuitem
因为我们必须在跳转到prefil.xhtml
页面之前调用一个方法来更改 tabindex 。如果使用url
,则跳转到prefil.xhtml
页面后会调用该方法。
First, you can use the action field of the p:menuitem
, the method returns the address you want to skip to:
首先,您可以使用 的操作字段p:menuitem
,该方法返回您要跳转到的地址:
<p:menubar autoSubmenuDisplay="true">
<p:submenu label="Perfil">
<p:menuitem value="Editar" action="#{some.editar}" ajax="false"/>
<p:menuitem value="Ver" action="#{some.ver}" ajax="false" />
</p:submenu>
</p:menubar>
These two method do something to change the tabindex like this:
这两种方法可以像这样更改 tabindex:
public String editar() {
tabindex = 0;
return "verPerfil";
}
public String ver() {
tabindex = 1;
return "verPerfil";
}
Then the p:tabView
has an attribute named activeIndex
. It is the index of the active tab, its default value is 0
. So you can do as follows:
然后p:tabView
有一个名为 的属性activeIndex
。它是活动选项卡的索引,其默认值为0
。所以你可以这样做:
<p:tabView dynamic="true" activeIndex="#{some.tabindex}" >
<p:tab id="ver" title="Ver perfil">
<ui:include src="verPerfil.xhtml" />
</p:tab>
<p:tab id="editar" title="Editar perfil">
<ui:include src="editarPerfil.xhtml" />
</p:tab>
</p:tabView>
Then each menuitem will activate the corresponding tab.
然后每个菜单项将激活相应的选项卡。