7 Replies Latest reply on Dec 13, 2010 4:42 PM by adnanqureshi

    How to share session data between portlets

      Hi,

      i'm looking for a way to share session attributes between portlets deployed in individual wars.

      I have tried to set/get data in the portletSession with PortletSession.APPLICATION_SCOPE but the data is not actually shared between the portlets.

      I think this is because these portlets are deployed in individual war files.

      The portal used is v2.6.7, so no jsr-286 ....

      Any help will be appreciated, thanks

        • 1. Re: How to share session data between portlets

          oki managed to share data across the portlets by getting the portalRuntimContex with Navigation.getPortalRuntimeContext() and then the portal session.


          BUT this does not work with richfaces a4j requests ....

          those requests are directly targeted to the webapp and do not go through the portal servlet, so there is no "portal" data in the request, context, session ...

          I wondered if i could access a portal MBean in which i could get access to the current sessions but i have no idea if there is such a MBean ...

          could someone give me some help ?
          thanks.

          • 2. Re: How to share session data between portlets

            Insted of using portletSession, you can use HttpSession object to store such information, try this code snippet:

            
            import javax.security.jacc.PolicyContext;
            import javax.security.jacc.PolicyContextException;
            import javax.servlet.http.HttpServletRequest;
            import javax.servlet.http.HttpSession;
            
            request = (HttpServletRequest) PolicyContext.getContext("javax.servlet.http.HttpServletRequest");
            request = (HttpServletRequest) PolicyContext.getContext("javax.servlet.http.HttpServletRequest");
            
            HttpSession httpSession = request.getSession();


            • 3. Re: How to share session data between portlets
              natoine

              Isn't there a way to share attributes between portlets not in a same Application ?

              Isn't it possible to use the <shared-session-attribute> element in portlet.xml to share attributes through session between portlet not of a same application ?

               

              I have tried to set this element to true or to the attribute name but i'm not able to see attributes from a portlet to another.

              • 4. Re: How to share session data between portlets
                natoine

                I have tried your code in JBoss portal 2.7.2 and i got an error :

                java.lang.IllegalArgumentException: unknown handler key
                     at javax.security.jacc.PolicyContext.getContext(PolicyContext.java:280)

                Well JBoss 2.7.2 implements JSR 286 so i should be able to use the shared-session-attribute but it doesn't work better...
                • 5. Re: How to share session data between portlets
                  theute

                  There is no such thing as "shared-session-attribute" in the JSR-286

                  • 6. Re: How to share session data between portlets
                    natoine

                    Yeah you're right it's just an enhancement of JSR 286.

                    I thought it was in the final version of the JSR...

                    Sorry about that.

                    • 7. Re: How to share session data between portlets
                      adnanqureshi

                      Can anyone suggest any solution/workaround for sharing data across different pages?