3 Replies Latest reply on May 12, 2009 7:06 AM by aspdeepak

    Problem with PortletSession

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

      I need to perform certain logic when the user logs in.

      ie, for each session I need to perform certain logic, that too in start of the session.

      This is my code, where i get a PortletSession attribute IS_FIRST_LOAD which is obviously null at the start of every new session. Then i am setting some value, so that the IS_FIRST_LOAD attribute will not be null afterwards.

      Portlet A - doView() implementation

      String isFirst =(String) request.getPortletSession().getAttribute(IS_FIRST_LOAD);
       log.info(" IS_FIRST_LOAD (before) = "+isFirst);
      
      
       if ( isFirst == null) { // if this is the first time loading
       request.getPortletSession().setAttribute(IS_FIRST_LOAD,"false",PortletSession.PORTLET_SCOPE);
      
       log.info(" showing the default charts(COLLECTION since IS_FIRST_LOAD )");
      
      
       log.info(" IS_FIRST_LOAD (after) = "+request.getPortletSession().getAttribute(IS_FIRST_LOAD));
      
       ..............................................
       ..............................................
      
       }



      In my case the PortletA's doView() will be called more than once.
      let's say minimum of 3 times. before the page gets completely rendered.


      when PortletA's doView() called for the first time the PortletSession attribute returns null so the logic works fine, (note: that the page is still not rendered completely).
      when it is called for 2 nd time PortletSession attribute returns null, which is not desirable,

      when it is called for 3rd time PortletSession attribute returns non null, and from here on every thing is working fine.


      So what is the reason behind the clearing of the PortletSession ?


      Any help is greatly appreciable.

        • 1. Re: Problem with PortletSession

          I some how found that there is an inconsistent (may be) behavior of PortletSession attributes, since the stored values vanishes after page rendering.

          To be more precise the values become null after the page refreshes, I don't know whether this is a bug.

          But I started using PortalSession object for storing the information

          My new implementation

          String isFirst =(String) Navigation.getPortalRuntimeContext().getSession().getAttribute(IS_FIRST_LOAD);
           log.info(" IS_FIRST_LOAD (before) = "+isFirst+" for user["+request.getUserPrincipal()+"]");
          
           if ( isFirst == null) { // if this is the first time loading
           Navigation.getPortalRuntimeContext().getSession().setAttribute(IS_FIRST_LOAD,"false");
           log.info(" showing the default charts(COLLECTION since IS_FIRST_LOAD )");
           log.info(" IS_FIRST_LOAD (after) = "+Navigation.getPortalRuntimeContext().getSession().getAttribute(IS_FIRST_LOAD));
          
           .............................................................
          
           .............................................................
          }
          


          Here

          Navigation.getPortalRuntimeContext().getSession()


          returns the PortalSession

          • 2. Re: Problem with PortletSession
            je.a.le

            you should look for PortalEventListener.
            when user login, logout or session expire, your listener will get a callback. You can set your portalsession attribute here.

            • 3. Re: Problem with PortletSession

              Thanks je.a.le for your solution
              It would be the optimal solution for handling the user related events.

              But I still can't understand why the PorteltSession gets cleared(null), when the portlet reloads.

              But this is not the case in PortalSession it lives through out the user session.