I just confirmed that Ajax.oncomplete() works as designed even when executed during/via preRenderView event. OmniFaces 'Ajax' utility is for 'Ajax' requests. I was under the assumption that OmniFaces Ajax.oncomplete() would send javascript to client during preRenderView on a FPR (full page refresh or non-AJAX request).
Why is OmniFaces Ajax utility's oncomplete() not working when invoked by preRenderView event?
Question
My preRenderView event invokes OmniFaces Ajax utility's oncomplete() method to execute javascript on the client. I just tested this, and the javascript is not executed on the client.
My f:event is below.
<f:metadata>
<o:enableRestorableView/>
<f:event type="javax.faces.event.PreRenderViewEvent" listener="#{pageNavigationController.preRenderView()}"/>
</f:metadata>
My pageNavigationController.preRenderView() is below,
public void preRenderView() {
if (initLayoutForPage) {
// initialize layout for page
layoutController.initializeForPage(page);
initLayoutForPage = false;
}
if (usersController != null) {
usersController.preRenderView();
}
}
which calls usersController.preReviewView() below, which invokes Ajax utility's oncomplete().
public void preRenderView() {
Ajax.oncomplete("document.getElementById('menuBarForm:btnLogout').click();");
}
Currently in production, the javascript above works as designed; this javascript is called as follows.
<script>window.onbeforeunload = function() { document.getElementById('menuBarForm:btnLogout').click(); }</script>
So, why is the javascript not being executed on the client?
EDIT: I no longer need this functionality as I just figured out a workaround for the original problem, but I would appreciate an answer to this question. Thanks. :)
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow