3 Replies Latest reply on May 12, 2009 7:15 AM by anbazhagan prasanna

    Handling PortalSessionEvent.SESSION_DESTROYED event

    anbazhagan prasanna Newbie

      Jboss App Server V 4.2.2
      Jboss Portal - V 2.7.0
      DB - Mysql 5.0

      I have written a separate listener class Cem4mPortalEventListener implementing PortalEventListener . I have made the necessary mbean injections and i am also successful in loggig all portal events.

      But now I need to make my portlets to be aware of the PortalSessionEvent.SESSION_DESTROYED event.

      To be more precise i need to display session expired message on the portlets or atleast i need to redirect the page to the login automatically.

      I have even tried setting the 'Event Listener Binding' as 'session_listenter' for the corresponding page and also portal, through the admin console, but it does'nt solve my problem.

      how can i achieve this automated 'session destroyed event' handling.

        • 1. Re: Handling PortalSessionEvent.SESSION_DESTROYED event
          je le Newbie

          Why not using a portalsession attribute ??
          login -> set
          logout or session expired -> unset
          in your portlet, redirect to the appropriate jsp according of this attribute state.

          • 2. Re: Handling PortalSessionEvent.SESSION_DESTROYED event
            anbazhagan prasanna Newbie

            Thanks for your reply.

            But my problem was to redirect the user to a automatically to a specified page, lets say login page.

            Also I tried using filters, but after session expiration, those filters could'nt be reached.



            I have solved this problem in a much simpler way, using javascript.

            All you need to do is just add this script to index.jsp of your respective layout folder since it is the container for all your portlets

            <script type="text/javascript">
            
            var timerId = null;
            var ttl = <%= request.getSession().getMaxInactiveInterval() * 1000 %>;
            function portalSessionTimeout() {
            alert('session expired');
            window.location.reload();
            
            // if you need specific page redirection
            //window.location.replace('<PAGE_URL>');
            //window.focus();
            
            }
            
            function initialSessionTimeout(){
            //alert('initialSessionTimeout()' + ttl );
            timerId = setTimeout('portalSessionTimeout()',ttl);
            }
            
            function resetSessionTimeout(){
            clearTimeout(timerId);
            timerId = setTimeout('portalSessionTimeout()',ttl);
            }
            
            
            </script>
            
            
            


            you need to invoke the initialSessionTimeout() in elements onload

            <body id="body" onload="initialSessionTimeout()">


            Note:
            if you have partial refresh enabled don't forget to call resetSessionTimeout() on each of your form submits (within the portlets) that may lead to inter portlet communications

            Reason:
            Remember IPC calls may lead to partial refersh and not the complete page reload, so the the ttl has to be reset, else even if the session is alive the page will be redirected because of wrong ttl



            • 3. Re: Handling PortalSessionEvent.SESSION_DESTROYED event
              anbazhagan prasanna Newbie

               

              But my problem was to redirect the user to a automatically to a specified page, lets say login page.


              Means that the redirection need not require any user interaction.

              Also some of the form submit buttons, that leads to IPC, becomes unresponsive after session timeout; due to partial refresh.

              So that only I chose for java script.