Going to a particular tab

Asked

Viewed 358 times

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 tab or register.

1 answer

1

To work you would need to update the p:tabView, for such:

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

2 - For menu items, you can update 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" />

Recommending:

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

  • I don’t know what happens, but it should work...:/ It looks like the action doesn’t work, don’t arrow the tabIndex.

  • Try printing a text in one of the methods (register or query) to see if it displays. Note: If you have a Javascript error it doesn’t even go to the next phase of JSF. Try opening the browser’s javascript console and see what happens.

  • Hy Cold, Thanks for the help.. He is already entering the method and setting the values. But since scopo is of the View type when redirecting it loses all data.

  • Then change his scope, because that way everything is working right (being @Viewscoped)

  • It’s changed to Sesssion consumed a lot of memory because I have a table too.. rsrs And I ended up finding a Flahsscoped that saves the Object or value that Voce wants in memory. Inside the method vc makes the change. &#xA;&#xA;public String redirecionarComFlash() {&#xA;&#xA;FacesContext instance = FacesContext.getCurrentInstance();&#xA;&#xA;ExternalContext externalContext = instance.getExternalContext();&#xA;externalContext.getFlash(). put("key", value); externalContext.getFlash(). setKeepMessages(true); Return URL + "? faces-redirect=true"; }

  • If this works I will post here.. Again Thank you for making logic available!

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.