Custom validation when changing tab in p:Wizard

Asked

Viewed 295 times

0

I have the following p:

<p:messages id="msgs" showDetail="false" autoUpdate="true"
                        closable="true" />
<p:wizard flowListener="#{caixaRecebimento_MB.onFlowProcess}" showNavBar="false" widgetVar="wRecebimento" styleClass="ms-botao" id = "wRecebimento" >
            <p:tab title="Documento" id="tabI">
                <ui:include src="/WEB-INF/templates/recebimento/RecebimentoDocumento.xhtml" />
            </p:tab>
            <p:tab title="Fechamento" id="tab1">
                <ui:include src="/WEB-INF/templates/recebimento/RecebimentoFechamento.xhtml" />
            </p:tab>
            <p:tab title="Ajuste Matricula" id="tab2">

            </p:tab>
            <p:tab title="Assinatura" id="tabF">

            </p:tab>
    </p:wizard>

    <hr />
    <p:commandButton id="btVoltar" widgetVar="btVoltar"  value="Voltar"  onclick="PF('wRecebimento').back();"  styleClass="ms-botao" icon="fa fa-arrow-left" 
        disabled="#{caixaRecebimento_MB.dasabilitaVoltar}" update="btVoltar btAvancar"/>
    <p:commandButton id="btAvancar" widgetVar="btAvancar" value="Avançar"  onclick="PF('wRecebimento').next();"  styleClass="ms-botao" icon="fa fa-arrow-right" iconPos="rigth" 
        disabled="#{caixaRecebimento_MB.desabilitaAvancar}" update="btVoltar btAvancar"/>

However I would like to do a custom validation when switching tabs, and so I did through the onFlowProcess method

public String onFlowProcess(FlowEvent event) {
    if(event.getOldStep().equals("tabI")){
        if(loteDeVenda.getItensLoteDeVenda().size()<2){
            FacesUtil.addErrorMessage("Não é possivel avançar sem incluir um item");
            //return event.getOldStep();
            return " ";
        }
    }

    if(event.getNewStep().equals("tabI")){
        this.desabilitaAvancar = false;
        this.dasabilitaVoltar = true;
    } else if(event.getNewStep().equals("tabF")){
        this.desabilitaAvancar = true;
        this.dasabilitaVoltar = false;
    } else {
        this.desabilitaAvancar = false;
        this.dasabilitaVoltar = false;
    }

    return event.getNewStep();
}

It even works, but when the validation should prevent progress I have some problems.

if return " " goes to last tab.

If you return Event.getOldStep() to stay in the current tab, the messages appear but then delete, as if you had refreshed the screen. that is until it remains in the tab as expected but the user is left without knowing why.

  • Friend, have you tried returning the id of p:Tab that you would like it to remain? Type "Tabi";

  • I did what you suggested. Navigation works, but the message keeps popping up and disappearing quickly

No answers

Browser other questions tagged

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