Partial AJAX calls don't handle container session timeouts

UI Components for JSF
Post Reply
cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

27 Jan 2012, 14:25

Problem with phaselistener is that it gets executed on every single request, exception handler is executed when something goes wrong which is ideal. Still it is a good trick for JSF 1.2 users.

ltune
Posts: 125
Joined: 20 Jul 2011, 20:25
Contact:

27 Jan 2012, 14:28

optimus.prime wrote:Problem with phaselistener is that it gets executed on every single request, exception handler is executed when something goes wrong which is ideal. Still it is a good trick for JSF 1.2 users.
Its, still a good trick for JSF2.1 users, but I recognize the benefit of exception listener;)
EDIT: Maybe especially for users paranoid about security who want to check at every single RequestCycle whether the World is still ok ;)
Busy applying primefaces patches to my local repo at /dev/null

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

27 Jan 2012, 18:04

Thank you ALL! I appreciate this topic and your responses. Bookmarking this topic for later reference.
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

User avatar
benignoms
Posts: 62
Joined: 18 Jun 2010, 05:56
Location: Brazil
Contact:

30 Jan 2012, 03:25

Dealing Gracefully with ViewExpiredException
http://weblogs.java.net/blog/edburns/ar ... ption-jsf2
7ec Solutions http://www.7ec.com.br/

Mojarra 2.1.6
PrimeFaces 4.0
PrimeFaces Extensions 1.1.0
GlassFish Server 3.1.2

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

30 Jan 2012, 11:28

Hello Cagatay,

Have you tried your solution for DataTable pagination / sorting? Do you see the "Ooops" dialog when you click on any DataTable's page in the expired web app? In PF 2.2.1 we had (have) a lot of use cases where ExceptionHandler doesn't catch ViewExpiredException.

I would also invalidate session when ViewExpiredException occurs (session.invalidate()) because ViewExpiredException doesn't mean that session got invalidated. There are scenarios beyond session expriration which cause the same exception. Especially working in several browser tabs with the same web app.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

mores
Posts: 64
Joined: 01 Dec 2010, 05:04

22 Feb 2012, 19:32

What if the webapp is protected by a filter like http://www.jasig.org/cas

The session is gone then the filter will redirect to a login page. The exception-handler-factory can never actually be called.

CAS works well for non-ajax requests but fails when using a ajax page.

What changes would need to occur on the CAS filter such that primefaces sees the redirect when using ajax ?
Or is something else needed in primefaces to catch the redirect ?
prime faces 7.0.11
jsf 2.3.9
tomcat 9.0.50

mores
Posts: 64
Joined: 01 Dec 2010, 05:04

24 Feb 2012, 18:06

I have boiled ajax error catching down to 2 scenarios:

1. How to deal with an AJAX page when tomcat is down:

Code: Select all

Status Code 503
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>503 Service Temporarily Unavailable</title>
</head><body>
<h1>Service Temporarily Unavailable</h1>
<p>The server is temporarily unable to service your
request due to maintenance downtime or capacity
problems. Please try again later.</p>
<hr>
<address>Apache/2.2.20 (Ubuntu) Server Port 80</address>
</body></html>
2. How to deal when session is expired:

Code: Select all

Status Code 302
Location=https://server.com/cas/login?TARGET=http%3A%2F%2Fserver.com%2Fwar%2Fjob%2FlistTask.jsf
I tried

Code: Select all

<p:confirmDialog id="timeout" header="Oooops!!!" severity="alert" visible="#{not empty param['TARGET']}" message="View has expired." widgetVar="confirmDlg">
            <p:commandButton type="button" value="Whatever" onclick="confirmDlg.hide()" />
</p:confirmDialog>
but it does not seem to work.

I tried it with 3.1.1 and 2.0.9 JSF
prime faces 7.0.11
jsf 2.3.9
tomcat 9.0.50

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

24 Feb 2012, 18:18

mores wrote:What if the webapp is protected by a filter like http://www.jasig.org/cas

The session is gone then the filter will redirect to a login page. The exception-handler-factory can never actually be called.

CAS works well for non-ajax requests but fails when using a ajax page.

What changes would need to occur on the CAS filter such that primefaces sees the redirect when using ajax ?
Or is something else needed in primefaces to catch the redirect ?
I'm trying to use Filter too, which checks a UserManager/LoginBean, and it redirects to Login page if LoginBean == null or userIsLoggedIn() == false. I recognize the same behavior, and exception handler factory not called. I haven't finished trying out different approaches.

In this post, Best way to implement user login page in JSF, BalusC recommends filter over a phaseListener. So, this is the reason why I went with a filter, but I wonder if phaseListener is better for AJAX and non-AJAX.
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

mores
Posts: 64
Joined: 01 Dec 2010, 05:04

24 Feb 2012, 20:22

I feel like I am getting close. I am looking for a simple client side error routine.

In a plain jsf/ajax page without primefaces I can do this:

Code: Select all

<h:outputScript name="jsf.js" library="javax.faces" target="head"/>
        <script type="text/javascript">
                jsf.ajax.addOnError(function() {alert("Please refresh your browser.");});
        </script>
If I add that same code to a primefaces page, then I click on a primefaces component I never see the alert.

Is primefaces catching that error ? If so can it either propagate it up so I can catch it or present a similar alert that can have a custom message ?

Icefaces has a client side error handler:

Code: Select all

var iceErrorCallback = function iceHandleError(statusCode, responseTxt, responseDOM) {
    //Handle all errors by simply redirecting to an error page
    window.location.href = "./generalError.xhtml";
}
http://wiki.icefaces.org/display/ICE/Ha ... Exceptions
prime faces 7.0.11
jsf 2.3.9
tomcat 9.0.50

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

20 Mar 2012, 23:23

I added the following to <head>...</head>

Code: Select all

<meta http-equiv="refresh" content="#{session.maxInactiveInterval};url=login.jsf" />
Got it from URL below (another great BalusC 'answer'/solution):

http://stackoverflow.com/questions/4992 ... in-jsf-2-0

I also have loginFilter in place, but the code above is really no good for AJAX/PPR, since entire page does not refresh, and page refreshes when timer runs down. Maybe I should add some type of session == null && session.maxInactiveInterval. Actually, I'm thinking of adding more non-AJAX requests to force full-page refresh... only for the menuitems in the main/page menubar. :)
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 38 guests