4 Replies Latest reply on Nov 1, 2006 4:47 PM by bmcgovern

    Using PortletSession, sharing objects between portlets

    bmcgovern

      Im using the following code setting a simple string in the portlet session's APPLICATION scope in portlet A. Reading it with portlet B. and its always returning null in portlet B. I'm missing something simple can anyone clue me in?


      Portlet A -- works just fine

      java.util.Date zDate = new java.util.Date();
      PortletSession zSession = request.getPortletSession();
      zSession.setAttribute("foo.timestamp", zDate.toString(), PortletSession.APPLICATION_SCOPE);
      System.out.println("Session Date ::" + (String)zSession.getAttribute("foo.timestamp", PortletSession.APPLICATION_SCOPE));


      Portlet B -- returns null.
      PortletSession zSession = request.getPortletSession();
      System.out.println("Session Date ::" + (String)zSession.getAttribute("foo.timestamp", PortletSession.APPLICATION_SCOPE));
      


        • 1. Re: Using PortletSession, sharing objects between portlets
          bmcgovern

          Update: The session ID accross both portlets is identical. They are in separate war files - does that make a difference? Any answers appreciated, I'm stuck here.

          • 2. Re: Using PortletSession, sharing objects between portlets
            bmcgovern

            In case anyone had the same issue, It was because both portlets were in different wars. Putting them in the same war fixed it. Whats wierd though is that when they were in separate wars, the session ID across both was identical. However niether portlet could read eachothers attributes.

            • 3. Re: Using PortletSession, sharing objects between portlets

              The J2EE spec requires different sessions for different WAR files , even if the sesison id is the same. That's why you see what you see.

              However: JBossPortal has a configuration option where all portlet WARs can be configured to use the Portal's session (I don't remember where it is though ;) . In other words: you can configure the portal to use only one session across all WAR files. This was done to allow for clustered session support.

              • 4. Re: Using PortletSession, sharing objects between portlets
                bmcgovern

                Think you could help me hunt that setting down? I have a new problem where i have a non portal webapp that has to be deoployed as a different war. It has to read both my portlets session vars and visa versa.

                Im reading TONS of contradictory posts saying that it can be done with the servlet container descriptor within jboss by setting the emptySessionPath="true" but that doesnt work. Any ideas? really appreciate it.