views:

39

answers:

1

Hi there,

I'm working on some portlets which I lay on Springs Portlet MVC framework. Now one question comes around: In these portlets I need some session objects (user info, etc) - to create this objects I was thinking of using a filter. My question is now: Do I have to declare my filter on normal webapp context (web.xml) or do I need to place the filter on portlet level? (placing portlet filters on portlet.xml)

If I'm not completely wrong all spring portlets run in the spring context which has access to the normal webapp context, so it should be enough do declare a filter as DelegatingFilterProxy where my session objects are created.

Am I wrong with this logic?

Update:

Ok - maybe I want something impossible: I just want to create a session bean with user information if an user logs into the portal (JBoss Portal). I tried filter/listener to achieve this but not one of my approaches works. With porting my JSR-168 portlets to Spring supported portlets I hoped this could be achievable.

I placed a filter into my web.xml but this is only triggered, if the user logs out - not on login.

+1  A: 

As of JSR 286 (Portlet 2.0):

The PortletSession interface defines two scopes for storing objects, APPLICATION_SCOPE and PORTLET_SCOPE.

There are also some other options for configuring your session handling (see the spec).

By and large, each portlet in your portlet.xml has its own session (portlet scope). This is stored in the HTTP session (application scope) with a key of the form javax.portlet.p.<ID>?<ATTRIBUTE_NAME>). If you have two instances of the same portlet, each will have its own session.

So, how you go about this depends on the scope you want your session variable to have.

McDowell