I’m trying to handle a ViewExpiredException exception on an ajax call using primefaces 2.2.1 on glassfish 3.1. I have an ajaxStatus like this:
<p:ajaxStatus id="ajaxStatus"
onstart="startAjaxDisplay()"
onerror="ajaxErrorHandler()"
oncomplete="endAjaxDisplay()"/>
The onstart and oncomplete get called as expected. I know the ajaxErrorHandler() works because I put it in oncomplete instead and it got called. All it’s doing right now is popping up an alert(). I set up my test and the response from the server looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<partial-response>
<error>
<error-name>class javax.faces.application.ViewExpiredException</error-name>
<error-message><![CDATA[viewId:/index.xhtml - View /index.xhtml could not be restored.]]></error-message>
</error>
<changes>
<extension primefacesCallbackParam="validationFailed">{"validationFailed":false}</extension>
</changes>
</partial-response>
That’s all as expected except the onerror just doesn’t get called. Am I misunderstanding how this is supposed to work?
The onerror handler will be not called, because ViewExpiredException is not an AJAX error, but a JSF during the construction of the view that is already expired (the session expired).
PrimeFaces ajax component not handle this situation as an error.
In my solution (JSF2+PrimeFaces3) I investigate the ajax response from the server and search for an JSF error message. See the most simple example below: