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:
<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?
If you want to do this.You can’t use the
urlin thep:menuitembecause we must call a method to changing the tabindex before skipping to theprefil.xhtmlpage. If you use theurl, the method will be invoked after we skip to theprefil.xhtmlpage .First, you can use the action field of the
p:menuitem, the method returns the address you want to skip to:These two method do something to change the tabindex like this:
Then the
p:tabViewhas an attribute namedactiveIndex. It is the index of the active tab, its default value is0. So you can do as follows:Then each menuitem will activate the corresponding tab.