Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Omnifaces - FullAjaxExceptionHandler - f:ajax onevent status is success

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.

like image 592
jc12 Avatar asked Jan 24 '26 11:01

jc12


1 Answers

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.

like image 193
BalusC Avatar answered Jan 27 '26 00:01

BalusC