How to set the active tab in the "Charts" tab?

I have a menu in which there are two elements in a submenu that call up 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> 

On this page, I have a tab 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 to configure the active tab so that each menu item activates the corresponding tab?

+7
source share
1 answer

If you want to do it. You cannot use the url in p:menuitem , because we must call the tabulation method before going to the prefil.xhtml page. If you use url , the method will be called after going to the prefil.xhtml page.

First, you can use the p:menuitem action field, the method returns the address you want to skip:

 <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 methods do something to modify tabindex as follows:

 public String editar() { tabindex = 0; return "verPerfil"; } public String ver() { tabindex = 1; return "verPerfil"; } 

Then p:tabView has an attribute called activeIndex . This is the index of the active tab, the default value is 0 . So you can do the following:

 <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 menu item activates the corresponding tab.

+24
source

All Articles