You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-user@portals.apache.org by James Dixon <Ja...@canberra.edu.au> on 2005/10/10 09:14:55 UTC

Sharing session variables between portlets.

This SHOULD be easy, and what I've done SHOULD work, so I'm at a bit of a
loss as to why it is not working.  I'm using Jetspeed2 M3 on Tomcat 5.0.28.
 
Here's what happens:
 
1)  I set a session variable in the  processAction method of portlet A:
 
  PortletSession session = actionRequest.getPortletSession(true);
  String x = actionRequest.getParameter("x");
  session.setAttribute("x",x,PortletSession.APPLICATION_SCOPE);
 
2) at the next render, in portlet A, the session variable is recognised with
the following code:
 
  if(session.getAttribute("x",PortletSession.APPLICATION_SCOPE)!=null)
  {
 
writer.write("<br>X:"+(String)session.getAttribute("x",PortletSession.APPLIC
ATION_SCOPE));
  }
  else
  {
   writer.write("<BR>No X session variable");
  }
  
However, in Portlet B, no session variable is found using the same code, and
my (pretty!) error message is displayed.
 
The only thing I can find that might be a clue is that both portlets need to
be in the 'same portlet application' to share the session.  In an example I
was using as my guide, this meant that the <portlet> tags of portlet A and B
were contained in the *one* Portlet.xml , and associated with only the one
<portlet-app> tag - with jetspeed, each different application has it's own
portlet.xml file.  I have ensured that the portlet-app tag in both files
read:
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="UCPP"
version="1.0"
xsi:schemalocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd
http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">

I assume this will make them part of the same portlet application?
 
Is there some other configuration I am missing?  Could this be a problem
with the way Jetspeed congregates its portlet.xml files?  
 
Grateful for any advice.
 
Thanks
 
James
 

RE: Sharing session variables between portlets.

Posted by James Dixon <ja...@canberra.edu.au>.
Thanks Ate, that has cleared things up a little.

But just for clarification:  there is no way share session data between
different web applications within the same Portal? Or if there is, how is
that done?



-----Original Message-----
From: Ate Douma [mailto:ate@douma.nu] 
Sent: Monday, 10 October 2005 6:10 PM
To: Jetspeed Users List
Subject: Re: Sharing session variables between portlets.

James Dixon wrote:
> This SHOULD be easy, and what I've done SHOULD work, so I'm at a bit 
> of a loss as to why it is not working.  I'm using Jetspeed2 M3 on Tomcat
5.0.28.
>  
> Here's what happens:
>  
> 1)  I set a session variable in the  processAction method of portlet A:
>  
>   PortletSession session = actionRequest.getPortletSession(true);
>   String x = actionRequest.getParameter("x");
>   session.setAttribute("x",x,PortletSession.APPLICATION_SCOPE);
>  
> 2) at the next render, in portlet A, the session variable is 
> recognised with the following code:
>  
>   if(session.getAttribute("x",PortletSession.APPLICATION_SCOPE)!=null)
>   {
>  
> writer.write("<br>X:"+(String)session.getAttribute("x",PortletSession.
> APPLIC
> ATION_SCOPE));
>   }
>   else
>   {
>    writer.write("<BR>No X session variable");
>   }
>   
> However, in Portlet B, no session variable is found using the same 
> code, and my (pretty!) error message is displayed.
>  
> The only thing I can find that might be a clue is that both portlets 
> need to be in the 'same portlet application' to share the session.  In 
> an example I was using as my guide, this meant that the <portlet> tags 
> of portlet A and B were contained in the *one* Portlet.xml , and 
> associated with only the one <portlet-app> tag - with jetspeed, each 
> different application has it's own portlet.xml file.  I have ensured 
> that the portlet-app tag in both files
> read:
> <portlet-app
xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="UCPP"
> version="1.0"
> xsi:schemalocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0
> .xsd http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
> 
> I assume this will make them part of the same portlet application?
No.

Only portlets part of one web application and defined in one portlet.xml
belong to the same portlet application.

Read up on the JSR-168 specification chapter PLT.15 and especially PLT.19,
which starts
with:
"A portlet application is a web application, as defined in Servlet
Specification 2.3, SRV.9 Chapter, containing portlets and a portlet
deployment descriptor in addition to servlets, JSPs, HTML pages, classes and
other resources normally found in a web application. A bundled portlet
application can run in multiple portlet containers implementations."

>  
> Is there some other configuration I am missing?  Could this be a 
> problem with the way Jetspeed congregates its portlet.xml files?
Jetspeed implements the JSR-168 requirements, so you just need to bundle the
portlets A and B together and then it will work.

Regards, Ate


---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org


Re: Sharing session variables between portlets.

Posted by Ate Douma <at...@douma.nu>.
James Dixon wrote:
> This SHOULD be easy, and what I've done SHOULD work, so I'm at a bit of a
> loss as to why it is not working.  I'm using Jetspeed2 M3 on Tomcat 5.0.28.
>  
> Here's what happens:
>  
> 1)  I set a session variable in the  processAction method of portlet A:
>  
>   PortletSession session = actionRequest.getPortletSession(true);
>   String x = actionRequest.getParameter("x");
>   session.setAttribute("x",x,PortletSession.APPLICATION_SCOPE);
>  
> 2) at the next render, in portlet A, the session variable is recognised with
> the following code:
>  
>   if(session.getAttribute("x",PortletSession.APPLICATION_SCOPE)!=null)
>   {
>  
> writer.write("<br>X:"+(String)session.getAttribute("x",PortletSession.APPLIC
> ATION_SCOPE));
>   }
>   else
>   {
>    writer.write("<BR>No X session variable");
>   }
>   
> However, in Portlet B, no session variable is found using the same code, and
> my (pretty!) error message is displayed.
>  
> The only thing I can find that might be a clue is that both portlets need to
> be in the 'same portlet application' to share the session.  In an example I
> was using as my guide, this meant that the <portlet> tags of portlet A and B
> were contained in the *one* Portlet.xml , and associated with only the one
> <portlet-app> tag - with jetspeed, each different application has it's own
> portlet.xml file.  I have ensured that the portlet-app tag in both files
> read:
> <portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="UCPP"
> version="1.0"
> xsi:schemalocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd
> http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
> 
> I assume this will make them part of the same portlet application?
No.

Only portlets part of one web application and defined in one portlet.xml belong
to the same portlet application.

Read up on the JSR-168 specification chapter PLT.15 and especially PLT.19, which starts
with:
"A portlet application is a web application, as defined in Servlet Specification 2.3, SRV.9
Chapter, containing portlets and a portlet deployment descriptor in addition to servlets,
JSPs, HTML pages, classes and other resources normally found in a web application. A
bundled portlet application can run in multiple portlet containers implementations."

>  
> Is there some other configuration I am missing?  Could this be a problem
> with the way Jetspeed congregates its portlet.xml files?  
Jetspeed implements the JSR-168 requirements, so you just need to bundle the portlets
A and B together and then it will work.

Regards, Ate


---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org