Going to a certain tab

1

This is my menu:

<p:menubar>  
      <p:submenu label="Clientes">  
           <p:menuitem value="Cadastro" action="#{nomeBean.cadastrar} outcome="funcionario.xhtml" />  
           <p:menuitem value="Consulta" action="#{nomeBean.consultar}" outcome="funcionario.xhtml" />  
     </p:submenu>  
</p:menubar>
...    
<p:tabView dynamic="true" activeIndex="#{nomeBean.tabIndex}" >  
   <p:tab title="Cadastro">      
   </p:tab>  
   <p:tab title="Consulta">
      tenho aqui uma dataTable
   </p:tab>  
</p:tabView>

This is my Bean:

private int tabIndex;

public void cadastrar() {
  tabIndex = 0;
}

public void consultar() {
  tabIndex = 1;
}

public int getTabIndex() {
  return tabIndex;
}

So by clicking on the Query Menu, for example, it does not redirect to the query or registration tab.

    
asked by anonymous 30.10.2014 / 16:15

1 answer

1

In order to work you would need to update p:tabView , to do so:

1 - Define a id par to p:tabView (Example: TestTest);

2 - For the menu items, you can update the p: tabView after it finishes the asynchronous request to the server (in this case the index change):

<p:menuitem value="Cadastro" update="tabTeste" action="#{nomeBean.cadastrar} outcome="funcionario.xhtml" />

Recommendation:

You could do this at the JavaScript level, to avoid "interaction" with the server only to change well-defined indexes.

    
30.10.2014 / 16:26