2
votes

what I want is that the window, which opens to type in some information about a new user(name,password,..), stays open if a validaton error occurs. I already tried many solutions from other posts but it just doesn't stay open. After I clicked on the save button it closes the window. When I reopen the dialog I can see red highlight on the required (and invalid) field. I hope you guys can help me.. I'm trying to solve this shit for 2 days...

<p:commandButton id="save" value="Save" udate="save" icon="ui-icon-disk"
        ajax="false" validateClient="true"
        action="#{userBean.addUser()}" oncomplete="if (args &amp;&amp; !args.validationFailed) PF('newUser').hide()" />
                        <!-- oncomplete="if (!args.validationFailed &amp;&amp;args.saved) PF('newUser').hide();"  -->
                        <p:commandButton id="cancel" value="Cancel" immidiate="true"
                        oncomplete="PF('newUser').hide()" />
1
Where are you using a <p:dialog> in the presented code snippet? Is it hidden behind newUser? You are sending a full synchronous request by clicking a <p:commandButton> (labelled Save). Regarding that case, do you ever really think this oncomplete="if (args &amp;&amp; !args.validationFailed) PF('newUser').hide()" may work as you might have already guessed/imagined/envisioned/visualized?Tiny
Yes it is hidden behind newUser. Well according to this solution stackoverflow.com/questions/9195756/… , it should actually work yes.Ricky77719

1 Answers

2
votes

The culprit is here, on your save button:

<p:commandButton ... ajax="false" />

Ajax is disabled on the button. This button won't submit the form asynchronously anymore. This button will submit the form synchronously which always implies a full page refresh. In other words, this button behaves exactly like a standard <h:commandButton> without <f:ajax>. An old-fashioned Web 1.0 form submit. All ajax related attributes like oncomplete, update, process, etc are plain ignored.

It's not clear from the question why exactly ajax was turned off on that button. If this was just result of an unthoughtful mistake or an uncareful copypaste, then just remove it and world should be well.

However, if you have a legitimate technical reason to turn off ajax on it (e.g. because of having a <p:fileUpload mode="simple"> in that form), then you'd need to make use of <p:dialog visible> attribute. With this you can control if the dialog should be shown on page load or not.

E.g.

<p:dialog ... visible="#{formName.submitted and facesContext.validationFailed}">
    <h:form binding="#{formName}">

    </h:form>
</p:dialog>

Note: code is as-is. No additional bean properties. For sure not on binding!