6 Replies Latest reply on Mar 13, 2007 6:38 PM by sergeysmirnov

    Session Expired Handling with Ajax4jsf

    kfletcher2005

      I have read from the documentation a cryptic example of how to handle http session expiration using ajax4jsf.

      Here is the snippet from the documentation.....
      --------------------------------------------------------
      Beginning with Ajax4jsf version 1.0.5 it's possible to redefine also the "onExpired" framework method that is called on the "Session Expiration" event.

      A4J.AJAX.onExpired = function(loc,expiredMsg){

      // Custom Developer Code

      };

      Here the function receives in params:

      * loc - URL of the current page (on demand can be updated)
      * expiredMsg - a default message on "Session Expiration" event.

      Note:
      Until the version 1.0.5 the method can't be redefined on "Session Expiration" , a confirmation dialog with request for view reloading was always called.


      ------------------------------------ End of snippet.

      I put this javascript in my jsp, and put in an alert to see if the session expiration event was captured. I set my session expiration to 1 minute in my web.xml. But the alert never popped up. Does anyone have a real life example how to handle the session expiration using ajax4jsf? Thanks, Kent.

        • 1. Re: Session Expired Handling with Ajax4jsf
          robjellinghaus

          You will get better response posting this in the users forum. This forum is more for discussion of code changes to Ajax4jsf itself.

          • 2. Re: Session Expired Handling with Ajax4jsf

            You misunderstood the idea what it is for.

            A4J.AJAX.onExpired is fired when the browser sends the Ajax Request after the session is expired.

            It is not about popping up something on the client without any prior communication with server.

            • 3. Re: Session Expired Handling with Ajax4jsf
              kfletcher2005

              I don't understand you. I'm not trying to pop something up for production, just for a proof of concept to see if the thing works like I think. I would expect the browser to send a session expiration event to be fired, and the following script below to be invoked upon that event.

              A4J.AJAX.onExpired = function(loc,expiredMsg){

              //custom code here.... but for now, see if the thing works by putting in an //alert....

              alert("Hey dude, the session expired");

              };
              ------
              Given the code, wouldn't one expect a popup with said string (just as a sanity check). I'll post this question to user forum.

              • 4. Re: Session Expired Handling with Ajax4jsf

                browser cannot send a session expiration event as far as session is expiring on the server, but on the client side.

                The use case:

                A Bank officer launches the application and goes to the page with customer list
                Then he decides to have a lunch
                Then he decided to speak with coworker about something
                Then he decided to watch couple moves on youtube.com
                Finally, he returns back to the office and clicks the button on one of the record in the customer list for details.
                It was an Ajax button, actually. The Ajax request is sent to the server. As soon as the 1-minute session timeout developer set up for this application is already expired, the server sends the special Ajax response that contains the expiration event.
                The client code invokes A4J.AJAX.onExpired method.

                • 5. Re: Session Expired Handling with Ajax4jsf
                  kfletcher2005

                  LOL! Nice use case. Thanks for the clarification. So the magic trick is the user has to click an AJAX'd button (or command link), then we make a round trip to server, then server says hey wait a minute, your session is no good, then sends ajax response with expiration event info. Thanks.

                  • 6. Re: Session Expired Handling with Ajax4jsf

                    Yep. Now, we are on the same page.