I find this article to be useful for non-ajax request How to handle session expiration and ViewExpiredException in JSF 2? but I can't make use of this when I am submitting using an AJAX call.
Suppose in a primefaces dialog, I am making a post request using AJAX and session has already timed out. I see my page getting stuck.
How to fix this kind of scenario such that when I post using AJAX, I could redirect him to my view expired page and then forward him to the login page similar to the solution in the link above?
JSF2/Primefaces/Glassfish
I have included this in my ViewExpiredExceptionHandler class and it worked fine for me in WAS
Hope this helps
Exceptions which are thrown during ajax requests have by default totally no feedback in the client side. Only when you run Mojarra with project stage set to
Development
and use<f:ajax>
, then you will get a bare JavaScript alert with the exception type and message. But other than that, and in PrimeFaces, there's by default no feedback at all. You can however see the exception in the server log and in the ajax response (in the webbrowser's developer toolset's "Network" section).You need to implement a custom
ExceptionHandler
which does basically the following job when there's aViewExpiredException
in the queue:Alternatively, you could use the JSF utility library OmniFaces. It has a
FullAjaxExceptionHandler
for exactly this purpose (source code here, showcase demo here).See also:
I faced this problem, Requirement need to display a confirmation popup when user do any action after session gets timed out, my proposed solution was:
The MyRedirectEntryPoint should extends AuthenticationProcessingFilterEntryPoint and override commence method
Now you can simply bind a callback javascript function to catch the thrown 403 error and do what ever you want:
A merge between the answer of @BalusC and this post, I solved my problem!
My ExceptionHandlerWrapper:
My ExceptionHandlerFactory:
My faces-config.xml
I am using Mojarra 2.1.7 in Production mode with JBoss 7. After the session expires, AJAX calls return an error XML document. You can easily catch this error using the usual onerror handler of f:ajax.