2 Replies Latest reply on Jan 22, 2009 3:43 AM by Alexander Chubenko

    Graceful session expiration.

    Ilya Kalujny Newbie

      i`ve been looking around for implementing graceful session expiration, and i`ve stumbled into useful bits of information here and there, but never saw this all in one place.

      Here is a portion of main panel:

       <rich:modalPanel id="sessionExpiredPanel" zindex="2000"
       resizeable="false"
       minWidth="100" minHeight="100"
       width="100" height="100">
       <h:outputText value="Your session has expired." />
       </rich:modalPanel>
      
       <a4j:region>
       <script type="text/javascript">
       A4J.AJAX.onExpired = function(loc, expiredMsg) {
       Richfaces.showModalPanel('sessionExpiredPanel',{width:450, top:200});;
       };
       </script>
       <a4j:form>
       <a4j:poll id="sessioncheck" interval="620000" reRender="sessioncheck" />
       </a4j:form>
       </a4j:region>
      



      and here is what session time out is set to in web.xml

       <session-config>
       <session-timeout>10</session-timeout>
       </session-config>
      


      The code is quite self-explanatory, but i`ll just repeat it: the idea is to have a separate empty a4j:poll that pings the server in periods bit larger then your session expiration. When session is expired and poll fires A4J.AJAX.onExpired override kicks in.

      Hope this proves helpful to someone.