Question

i have validation for three components in a dialog, onblur of the components as follows:

<p:message for="idEstNumOfUser" display="icon" id="msgEstNumOfUser" />
<p:inputText id="idEstNumOfUser"
        placeholder="Estimated Number of Users"
        value="#{mybean.estimatedUserCount}" required="true" requiredMessage="Estimated Number of Users Is Required"
        maxlength="8" title="Estimated Number of Users"
        validatorMessage="Please enter digits only for 'Estimated Number of Users'"
        converterMessage="Please enter digits only for 'Estimated Number of Users'">
        <f:convertNumber />
<p:ajax event="blur" update=":betasignup:msgEstNumOfUser" />
</p:inputText>


<p:message for="idTxtFirstName" display="icon" id="msgFirstName" />
<p:inputText id="idTxtFirstName" placeholder="First Name"
    value="#{mybean.firstName}" required="true"
    requiredMessage="First Name Is Required" maxlength="100"
    title="First Name">
    <p:ajax event="blur" update=":betasignup:msgFirstName" />
</p:inputText>

<p:message for="idTxtLastName" display="icon" id="msgLastName" />
<p:inputText id="idTxtLastName" placeholder="Last Name"
    value="#{mybean.lastName}" required="true"
    requiredMessage="Last Name Is Required" maxlength="100"
    title="Last Name">
    <p:ajax event="blur" update=":betasignup:msgLastName" />
</p:inputText>

<p:messages id="messages"  autoUpdate="true"/>

my bean is has view scope.

CASE: when leaving first field empty and navigating to second field p:messages display message for first field, and when leaving second field empty and navigating to third field, p:messages clears messages for first field and displays only message for second field, and i want it to preserve old message (and remove the error message in case only error is fixed) and display both validation messages since first field and second field currently have validation errors.

EDIT: Dialog code

<h:form id="betasignup" title="#{msg['betasignup.text']}">
            <p:dialog id="dlgSignUp" widgetVar="signUpDialog" resizable="false"
                modal="true" header="#{msg['betasignup.header']}" styleClass="sign-up-dialog">

how i show the dialog:

<p:commandLink id="iam_interested2" styleClass="iam_interested"
                        oncomplete="signUpDialog.show()"
                        actionListener="#{myBean.init()}"
                        update=":betasignup">

please advise, thanks.

Was it helpful?

Solution

Set each ajax update tag with process="@form". I suspect the reason why a validation message is displayed for only a single component at a time is that each ajax request only processes a single component. As a result, only one component will ever fail validation at a single time and only one validation message will be queued. By setting each you'll ensure that each component in the form goes thru validation during processing and their respective validators will kick in.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top