It failed because you used ajax="false". This fires a full synchronous request which in turn causes a full page reload, causing the oncomplete to be never fired (note that all other ajax-related attributes like process, onstart, onsuccess, onerror and update are also never fired).
That it worked when you removed actionListener is also impossible. It should have failed the same way. Perhaps you also removed ajax="false" along it without actually understanding what you were doing. Removing ajax="false" should indeed achieve the desired requirement.
Also is it possible to execute actionlistener and oncomplete simultaneously?
No. The script can only be fired before or after the action listener. You can use onclick to fire the script at the moment of the click. You can use onstart to fire the script at the moment the ajax request is about to be sent. But they will never exactly simultaneously be fired. The sequence is as follows:
- User clicks button in client
onclickJavaScript code is executed- JavaScript prepares ajax request based on
processand current HTML DOM tree onstartJavaScript code is executed- JavaScript sends ajax request from client to server
- JSF retrieves ajax request
- JSF processes the request lifecycle on JSF component tree based on
process actionListenerJSF backing bean method is executedactionJSF backing bean method is executed- JSF prepares ajax response based on
updateand current JSF component tree - JSF sends ajax response from server to client
- JavaScript retrieves ajax response
- if HTTP response status is 200,
onsuccessJavaScript code is executed - else if HTTP response status is 500,
onerrorJavaScript code is executed
- if HTTP response status is 200,
- JavaScript performs
updatebased on ajax response and current HTML DOM tree oncompleteJavaScript code is executed
Note that the update is performed after actionListener, so if you were using onclick or onstart to show the dialog, then it may still show old content instead of updated content, which is poor for user experience. You’d then better use oncomplete instead to show the dialog. Also note that you’d better use action instead of actionListener when you intend to execute a business action.
See also:
- Understanding PrimeFaces process/update and JSF f:ajax execute/render attributes
- Differences between action and actionListener