I've a popup overlay page using JQuery. It has some fields and a submit button. Upon submit, the values of the popup should be server-side-validated. If all the values are successful, the popup page should close.
What i did is to validate the fields using <f:ajax>
then check if there are error messages in the backing bean using javascript. The javascript closes the popup if there are no error messages logged, and does nothing if errors are found.
Currently, what happens is that the popup closes before the listener is invoked.
Is there a way so that the ajax listener is invoked before the javascript onevent
validation?
Here is the commandLink that calls the validation:
<h:commandLink id="submitButton" value="submit">
<f:ajax execute="popupPage"
render="popUpDetails popupMessages"
onevent="closePopupDialogIfNoErrors"
listener="#{controller.saveAndValidatePageValues}" />
</h:commandLink>
And here is the jquery script used in the onevent
event:
function closePopupDialogIfNoErrors(){
if( #{backingBean.messages.size() == 0} ){
$("#popupDialog").dialog('close');
}
};