Question

I'm using Omnifaces FullAjaxExceptionHandler - which is working great, but when I do an ajax call and have an onevent function that is checking for status == 'success' it is still being called, even though the FullAjaxExceptionHandler has rendered an error page. (I'm using JSF(Mojarra 2.1.3 on glassfish 3.1.1)

JSF Code:

<h:commandButton value="myButton"> <f:ajax listener="#{myBean.myBeanFunction()}" render="someDiv" onevent="myFunction"/> </h:commandButton>

Javascript Code:

function myFunction(e) { if (e.status == 'success') { alert("Success"); } }

So I need some way of not executing the javascript function if the FullAjaxExceptionHandler is taking me to an error page.

Was it helpful?

Solution

You could check as follows if the returned XML response does not indicate that a render="@all" has been performed (which would indicate that the entire document will be replaced):

if (e.responseXML.getElementById('javax.faces.ViewRoot') == null) {
    // ...
}

That it works with oncomplete of a PrimeFaces command component is because it does not use the standard JSF ajax API for this and does things thus differently -more intuitively.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top