I have a form in a dialog like this:
<p:dialog id="panel" header="Inserisci" widgetVar="dlg1">
<h:form id="form">
<p:inputText id="username" value="#{userController.username}" />
<p:inputText type="password" id="password" value="#{userController.password}" />
<p:commandButton actionListener="#{userController.insert}" oncomplete="dlg1.hide();" value="Accept" />
</h:form>
</p:dialog>
A button "Insert" shows on click this dialog. When I click to Accept button the form is submitted with Ajax and validated. When response comes, the dialog closes in any case, whether the form is valid that it is not. How can I check if the form is valid in client-side oncomplete and close the dialog only if it is valid? By the way the validation works because if I open the dialog again after input wrong data, the invalid fields are surrounded by a red border. I already tried to change oncomplete with onsuccess but it didn't work because the ajax request still well sent even if the form is not valid.