Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Required validation depending on specific button not working in Wizard

I'm trying to implement the answer from BalusC in this post, but it is not working when I try to make the required condition depend on a button outside a Wizard, that I'm using to control the "back" and "next" of the wizard. How can achieve this?

<h:form id="form" enctype="multipart/form-data" acceptcharset="ISO-8859-1" >  

    <p:growl id="growl" sticky="true" showDetail="true"/>  

    <p:wizard id="wizard" flowListener="#{myBean.onFlowProcess}" showNavBar="false" widgetVar="wizardWV"> 

        <p:tab id="tab1" title="Tab 1"  >  
            <p:panel header="Panel for tab 1">  

                <p:message for="year" />
                <br /> 

                <table>
                    <tr>
                        <td>
                            <h:outputLabel value="Year: "  />
                        </td>
                        <td>
                            <p:inputMask 
                                id="year"
                                value="#{myBean.year}" 
                                required="#{not empty param[nextPanel.clientId]}"
                                requiredMessage="Year is required!"
                                style="width:70px;"  
                                mask="9999" 
                                maxlength="4" 
                            />
                        </td>
                    </tr>
                </table>
            </p:panel>
        </p:tab>

        <p:tab id="tab2" title="Tab 2"  >  
            <p:panel header="Panel for tab 2">  
            </p:panel>
        </p:tab>

    </p:wizard>

    <p:commandButton id="backPanel"  value="Back" onclick="PF('wizardWV').back();" styleClass="internalButton"  />
    <p:commandButton id="nextPanel" binding="#{nextPanel}" value="Next" onclick="PF('wizardWV').next();" styleClass="internalButton" />

</h:form> 
like image 309
reidestis Avatar asked Mar 05 '14 23:03

reidestis


1 Answers

why this question has not been answered? like @BalusC said, the answer is simple, just put @process="this"

<h:form>
    <p:wizard id="wizard" showNavBar="false" widgetVar="wizardWV">
        <p:tab id="tab0" title="Tab 0">
            <p:panel header="Panel for tab 0">
                blablabla
            </p:panel>
        </p:tab>

        <p:tab id="tab1" title="Tab 1">
            <p:panel header="Panel for tab 1">
                <p:message for="year" />
                <br />

                <h:panelGrid columns="2">
                    <h:outputLabel value="Year: " />
                    <p:inputMask id="year" value="#{myBean.year}" required="true"
                        requiredMessage="Year is required!" style="width:70px;" mask="9999"
                        maxlength="4" />
                </h:panelGrid>
            </p:panel>
        </p:tab>

        <p:tab id="tab2" title="Tab 2">
            <p:panel header="Panel for tab 2">
                blablabla
            </p:panel>
        </p:tab>
    </p:wizard>

    <p:commandButton value="Back" onclick="PF('wizardWV').back();" />
    <p:commandButton process="@this" value="Next" onclick="PF('wizardWV').next();" />
</h:form>

or better, to avoid duplicate ajax request

<p:commandButton type="button" value="Back" onclick="PF('wizardWV').back();" />
<p:commandButton type="button" value="Next" onclick="PF('wizardWV').next();" />

but i really don't see the point in using a custom nav bar for wizard in this case.


if you mean "skin" by mentioning "design", the right approach is to override PF CSS styles:

Wizard resides in a container element that style and styleClass attributes apply.
Following is the list of structural css classes.

Selector               Applies
.ui-wizard             Main container element.
.ui-wizard-content     Container element of content.
.ui-wizard-step-titles Container of step titles.
.ui-wizard-step-title  Each step title.
.ui-wizard-navbar      Container of navigation controls.
.ui-wizard-nav-back    Back navigation control.
.ui-wizard-nav-next    Forward navigation control.

But if you really mean "design", intended like features/functionalities, yes, you can interact with wizard by its "widget" and, like you did, define your own controls. In your specific case i don't see a "design" difference, i see a standard behavior of the wizard component, where current wizard tab is processed (and all its components validated) on next button pressed.

Validation is triggered ONLY for processed components (that are inside execution list), and you may control this list with process="..." attribute of any ajax component/event.

What you probably want is to change the default behavior of another component in that page wich processes @all or @form.

From what you say in your comment, you have at least another component in that page which has an ajax behavior, like a p:autocomplete and, probably, you are using PF < 4.0.

In this case you can add process="@this" to the p:autocomplete to prevent processing (and then validation) of other components inside the wizard tab, like your p:inputMask.


@Erick, the first thing that comes into my mind is this:

<p:wizard binding="#{wizardComponent}" ...>
    <p:tab id="tab0" ...>
        ...
    </p:tab>
    ...
</p:wizard>
<p:commandButton rendered="#{wizardComponent.step != 'tab0'}" value="Back" onclick="PF('wizardWV').back();" />
like image 190
Michele Mariotti Avatar answered Oct 01 '22 01:10

Michele Mariotti