Primefaces Tabview Component Disappears

Asked

Viewed 19 times

1

Hello, I am testing the Tabview component with mandatory fields included in each tab. I use ajax with update="@form" to update the component, but when I click on another tab, the Tabview bar simply disappears, after that, I click on the 'Continue' button, then it reappears.

I already tried to change the ajax update to update=":form:opL :form:tv :form:buttons", but it remained with the behavior of still validating the fields of the tab that was previously accessed along with the current tab, thus having to click more than once to validate only the current tab.

If someone has been through something of the kind and can guide me, I thank you from now on. Follow the codes.

Xhtml:

<h:form id="form">
<p:panel id="painel" header="Pessoas - Cadastro com TABVIEW">
    <p:outputLabel value="#{pessoasTabViewBean.activeIndex}" id="opL"/>     
        <p:tabView id="tv" widgetVar="tv" activeIndex="#{pessoasTabViewBean.activeIndex}"  dynamic="true" cache="false">            
        <p:ajax event="tabChange" listener="#{pessoasTabViewBean.controlarAbaSelecionada}"  update=":form:opL :form:tv :form:botoes"/>
            <p:tab title="Aba I" id="tab0">
                <ui:include src="/pages/abas/_aba_docPessoa.xhtml" />
            </p:tab>
            <p:tab title="Aba II" id="tab1">
                <ui:include src="/pages/abas/_aba_enderPessoa.xhtml" />
            </p:tab>
            <p:tab title="Aba III" id="tab2">
                <ui:include src="/pages/abas/_aba_contatoPessoa.xhtml" />
            </p:tab>
        </p:tabView>
        <h:panelGrid columns="2" id="botoes">
            <p:commandButton value="Voltar" process="@this" update=":form :mensagem" actionListener="#{pessoasTabViewBean.voltar}" />
            <p:commandButton value="Continuar" update="@form" process="@form" actionListener="#{pessoasTabViewBean.continuar}" />               
        </h:panelGrid>                      
    </p:panel>
</h:form>

Managedbean:

@SuppressWarnings("serial")
@ViewScoped
@ManagedBean 
public class PessoasTabViewBean implements Serializable{

private Pessoa pessoa;  
private Integer activeIndex;    
private TabView tabView;        
@PostConstruct
public void novo() {

    try {
        pessoa = new Pessoa();
        
    } catch (RuntimeException erro) {
        Messages.addGlobalError("Ocorreu um erro ao tentar gerar um nova pessoa.");
    }
}   

public String voltar(){
    
    String redirectPage = ""; 
    
    if (this.activeIndex == 0 || this.activeIndex == null) {
        redirectPage = "/pages/principal.jsf?faces-redirect=true"; 
    } else {
        this.setActiveIndex(--this.activeIndex);
    }
    return redirectPage;
}   

public String continuar() throws Exception{

    try {           
        
    } catch (Exception e) {
        
        throw new Exception(e.getMessage());
    } finally {
        this.setActiveIndex(++this.activeIndex);
    }       
    return StringUtils.EMPTY;       
}

public void controlarAbaSelecionada(TabChangeEvent event) {
    TabView tv = (TabView) event.getComponent();
    this.activeIndex = tv.getChildren().indexOf(event.getTab());
}   

...

No answers

Browser other questions tagged

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