2 Replies Latest reply on Feb 14, 2013 9:58 AM by Philip H

    do something on session timeout

    Philip H Newbie

      hi there.

      ive been looking up ideas on how to do something on a session timeout and came up with adding this to my web.xml:

       

      <context-param>

              <param-name>org.ajax4jsf.handleViewExpiredOnClient</param-name>

              <param-value>true</param-value>

      </context-param>

       

      and implementing a js on my testpage which looks like that:

       

      <?xml version='1.0' encoding='UTF-8' ?>

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

      <html xmlns="http://www.w3.org/1999/xhtml"

            xmlns:h="http://java.sun.com/jsf/html"

            xmlns:ui="http://java.sun.com/jsf/facelets"

            xmlns:rich="http://richfaces.org/rich"

            xmlns:f="http://java.sun.com/jsf/core"

            xmlns:a4j="http://richfaces.org/a4j">

          <h:head>

              <title>ANCORPUS</title>

          </h:head>

          <h:body>

              timeouttest

              <a4j:outputPanel ajaxRendered="true">

                  <script type="text/javascript">

       

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

       

          if(window.confirm("Custom onExpired handler "+expiredMsg+" for a location: "+loc)){

       

            return loc;

       

          } else {

       

           return false;

       

          }

       

      }

             

                  </script>

                  </a4j:outputPanel>

             

                  </h:body>

       

                  </html>

       

      But the frustating issue here is that just nothing happens.

      To be clear what i want is that if the session times out, i want a method called in my backing bean to do smth on the database.
      Is this the right way to do this and i just missed out some tiny detail or totally the wrong approach ?
      Thank you in advance

        • 1. Re: do something on session timeout
          Erdem YILMAZ Newbie

          hi,

          why do not prefer HttpSessionListener?

          here an example:

           

          import javax.servlet.http.HttpSessionEvent;

          import javax.servlet.http.HttpSessionListener;

           

          public class SessionListener implements HttpSessionListener {


              public void sessionCreated(HttpSessionEvent event) {


           

                  System.out.println("Session Created: " + event.getSession().getId());

                  System.out.println("Total Sessions: " + sessionCount);

              }

           

              public void sessionDestroyed(HttpSessionEvent event) {

                  System.out.println("Session Destroyed: " + event.getSession().getId());

                  System.out.println("Total Sessions: " + sessionCount);

              }

          }

           

          regards,

          Erdem

          • 2. Re: do something on session timeout
            Philip H Newbie

            thx a lot for your answer, its perfectly doing what i want. the funny thing is that i just looked it up 5 minutes before i read your answer. but thx a lot anyway.

             

            ONLY one thing might be important for anyone who has the same issue- you need to register that listener in the web.xml like this:

             

            <listener>

                    <listener-class>myPackage.NameOfMyListenerClass</listener-class>

            </listener>

            best wishes