aspose file tools*
The moose likes Portals and Portlets and the fly likes PortletSession and duplicate portlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Portals and Portlets
Bookmark "PortletSession and duplicate portlets" Watch "PortletSession and duplicate portlets" New topic
Author

PortletSession and duplicate portlets

Mike Halford
Ranch Hand

Joined: Jul 13, 2005
Posts: 31
Hi,
I've written a portlet which displays a directory structure that the user can navigate to access files. This is working fine. Putting it simply the directory structure and current state, ie which directory the user has navigated to, is stored in a TreeMap which is stored in the PortletSession.

The requirement is for the user to be able to view two directory structures so I have duplicated the portlet, so I have DirectoryPortlet1 and DirectoryPortlet2. I have each Portlet on a different page.

However, the problem is that if I navigate to a directory on one page, then when I look the other page then then the navigational state is the same. It appears that although I have two portlets they are sharing the same PortletSession. How do I can have a separate session for each portlet?
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

How are you accessing the session in the JSP page?

I'm wondering if you're using the HttpSession, rather than the PortletSession. The PortletSession is not shared amongst portlets, but the HttpSession.

Is that possible?

-Cameron McKenzie
Mike Halford
Ranch Hand

Joined: Jul 13, 2005
Posts: 31
Hi Cameron,
Great books I thought you may have spotted my deliberate mistake there but all I'm using to get the session is....
PortletSession portletSession = request.getPortletSession();
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

Ok, there goes the obvious.

What session scope are you using?

I'm wondering if anything is being put in a common scope, or context scope. Two different users don't get the same duplication, right? Like if you opened up an IE and Firefox browser, logged in both with the same username, the two browsers would be different, right?

There's no way you're using APPLICATION_SCOPE for the session data, instead of session scope?

It certainly seems like there's a central spot from which the client is reading data.

-Cameron McKenzie
Mike Halford
Ranch Hand

Joined: Jul 13, 2005
Posts: 31
I'm now explicitly using PortletScope, just to be on the safe side and it has made no difference. The behaviour is the same if I logon in another browser

I'm using a singleton to build the initial treemap. When the portlet calls the singleton it gets a copy of the TreeMap. The portlet copy of the TreeMap is kept in the PortletSession. The portlet initialises a view bean with data from the TreeMap, the view bean is added to the PortletSession.
Mike Halford
Ranch Hand

Joined: Jul 13, 2005
Posts: 31
Woops, it was me not cloning objects properly
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1



Silly goose.



-Cameron McKenzie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: PortletSession and duplicate portlets