samantha2015 0 Newbie Poster

I have a primefaces wizard which contain a simple form and a datatable. On clicking save, the record is displayed in the datatable which is just below the form. Now for the user to move on the next tab, he should at least enter a record such that he can proceed to the next tab. So I've done a check, on clicking next , it verifies if the list use to populate the datatable is empty or not. If not he can proceed. Now my problem is on clicking back ,validation is prompted. How can I prevent this? The validation should be prompted only when clicking next.

<p:wizard flowListener="#{CarComponent.onFlowProcess}"  showStepStatus="true">

            <p:tab id="model" title="Model">

                <p:panel>
                    <p:messages />
                    <h:panelGrid id="mdl" columns="2" styleClass="grid"
                        columnClasses="label,value">
                        <h:outputText
                            value="Date" />
                        <p:calendar id="date"
                            value="#{}"
                            required="true" converter="primefacesCalendarConverter"
                            pattern="dd/MM/yyyy" />

                    </h:panelGrid>
                </p:panel>
            </p:tab>


            <p:tab id="part">

                <p:panel>
                    <p:messages />
                    <h:panelGrid id="partdetails" columns="2" styleClass="grid"
                        columnClasses="label,value">
                        <h:outputText
                            value="PartNo:" />

                        <h:inputText id="partno"
                            value="#{..}"
                            required="false" maxlength="500">

                        </h:inputText>

                     <h:inputHidden
                      required="#{empty CarComponent.partList}"
                      requiredMessage="Please enter a Part." 
                       />

                        <h:panelGroup>
                            <p:commandButton image="save" ajax="false"
                                value="Save" process="@this,partno"
                                action="#{CarComponent.saveCarDetails(...)}" />
                        </h:panelGroup>
                    </h:panelGrid>
                </p:panel>


                <p:panel>
                    <h:panelGroup>
                        <p:dataTable id="dta_obj" editable="true"
                            value="#{CarComponent.partList}"
                            var="currentobj" rows="15" paginator="true"
                            paginatorPosition="bottom">
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText
                                        value="Part No:" />
                                </f:facet>
                                <p:cellEditor>
                                    <f:facet name="output">
                                        <h:outputText value="#{current.partno}" />
                                    </f:facet>
                                    <f:facet name="input">
                                        <h:inputText value="#{current.partno}" />
                                    </f:facet>
                                </p:cellEditor>
                            </p:column>


                        </p:dataTable>
                    </h:panelGroup>
                </p:panel>
            </p:tab>


            ...
        </p:wizard>

The flow listener is as follows:

 public String onFlowProcess(FlowEvent event) {


    if (event.getOldStep().contains("model")) {

        //some code here
    }

    if (event.getOldStep().contains("part")) {
        partList = car.getPart();
        if(partList.isEmpty()){

            String errorMsg="Please enter a Part.";

            FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_ERROR,errorMsg, ""));
            return event.getOldStep();
        }
    }

    return event.getNewStep();
}