I am using OmniFaces FullAjaxExceptionHandler and PrimeFaces. I added a command button in the errorPage.xhtml as follows:
<h:form>
<p:commandButton id="logoutButtonId" value="Redirect" actionListener="#{userMB.logout()}">
</h:form>
The error page gets displayed properly, but the button doesn't fire the method #{userMB.logout()}.
This is what I understand what happens in my setup:
FullAjaxExceptionHandler nicely displays errorPage.xhtml.It is only in the second click that the bean method gets called. Seems that on first load, the bean method doesn't gets bound to the object.
How do I implement adding a command button in an error page with an action/actionlistener being properly bound to an HTML component when using FullAjaxExceptionHandler?
This was what worked for me, a combination of the approach mentioned by BalusC in his answer below. It works in both IE and Firefox. It might need some tweaking for some cases but since the error page I got only has one form, I didn't bother to loop thru the forms.
var originalPrimeFacesAjaxResponseFunction = PrimeFaces.ajax.AjaxResponse;
PrimeFaces.ajax.AjaxResponse = function(responseXML) {
var newViewRoot = $(responseXML.documentElement).find("update[id='javax.faces.ViewRoot']").text();
if (newViewRoot) {
var viewState = $(responseXML.documentElement).find("update[id='javax.faces.ViewState']").text();
$('head').html(newViewRoot.substring(newViewRoot.indexOf("<head>") + 6, newViewRoot.indexOf("</head>")));
$('body').html(newViewRoot.substring(newViewRoot.indexOf("<body>") + 6, newViewRoot.indexOf("</body>")));
if (!$('input').attr("javax.faces.ViewState")){
var hidden = document.createElement("input");
hidden.setAttribute("type", "hidden");
hidden.setAttribute("name", "javax.faces.ViewState");
hidden.setAttribute("value", viewState);
hidden.setAttribute("autocomplete", "off");
$('form').append(hidden);
}
} else {
originalPrimeFacesAjaxResponseFunction.apply(this, arguments);
}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With