2

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()" />
Ricky77719
  • 43
  • 1
  • 5
  • Where are you using a `` in the presented code snippet? Is it hidden behind `newUser`? You are sending a full synchronous request by clicking a `` (labelled `Save`). Regarding that case, do you ever really think this `oncomplete="if (args && !args.validationFailed) PF('newUser').hide()"` may work as you might have already guessed/imagined/envisioned/visualized? – Tiny Jan 11 '15 at 18:35
  • Yes it is hidden behind newUser. Well according to this solution http://stackoverflow.com/questions/9195756/keep-pdialog-up-when-a-validation-error-occurs-after-submit , it should actually work yes. – Ricky77719 Jan 11 '15 at 19:44

1 Answers1

2

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!

Community
  • 1
  • 1
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
  • Hey Balus, thanks for the hint. By adding the visible attribute to the and also adding the binding to the solved the problem, the windows stays open until the right text was typed in. If someone does not understand the the visible attribute here is a nice explanation (also from Balus..:): [link](http://stackoverflow.com/questions/10050669/difference-between-rendered-and-visible-attributes-of-pdialog) – Ricky77719 Jan 12 '15 at 19:56