Custom Validation when changing tab in p: wizard

0

I have the following p: wizard

<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 changing tabs, and I did this using 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 validation should prevent you from moving forward I have some issues.

If return "" goes to last tab.

If return event.getOldStep () to remain in the current tab, the messages appears but soon goes out, as if it had given a refresh on the screen. that is until it stays on the tab as expected but the user does not know why.

    
asked by anonymous 07.12.2016 / 21:08

0 answers