Rounak
Rounak

Reputation: 181

How to use HTTP Session Scope in portlets ?

In my application there are 5 portlets accessing same bean class which is in session scope. My problem is, whenever I open a portlet, managed bean initializes. Managed bean should be initialize once in a session. In my case bean initializing 5 times. Can anyone tell me what is the root cause of that problem?

Here is my bean :

@ManagedBean(name="userManagementBean")
@SessionScoped
public class UserManagementBean {


public UserManagementBean() {

    System.out.println("In getter setter bean");

    sName=userManagementHelper.findScreenName();  

    directReport=new DualListModel<String>();
    addUserToGroupDual=new DualListModel<String>();
    addUserToGroupDual.getSource().clear();
    addUserToGroupDual.getTarget().clear();
            ............

Upvotes: 0

Views: 1345

Answers (2)

Avinash Singh
Avinash Singh

Reputation: 3787

JSR286 has user session based scope but it would depend on your portal server if it has the implementation for this as a Custom Scope for JSF.

I know for sure that Websphere portal 8.x supports this.

In Websphere portal 8.x you can specify your managed bean like,

@ManagedBean(name="userManagementBean")
@CustomScoped("#{portletApplicationSessionScope}")
public class UserManagementBean {

...

}

Have a look into your portal server documentation to see if it supports that.

You can use Apache JSF portlet bridge as you have updated that you are using liferay ,

It will expose Application Session Scope as EL,

Add it to application scope in portlet A

PortletSession session = request.getPortletSession();
session.setAttribute("name",name.getValue().toString(),PortletSession.APPLICATION_SCOPE);

and use in portlet B

PortletSession session = request.getPortletSession();
String value = session.getAttribute("name", PortletSession.APPLICATION_SCOPE).toString();

Your xhtml ,

<h:inputText id="itName" 
                required="true" 
                value="#{httpSessionScope.name}"/>

Upvotes: 0

partlov
partlov

Reputation: 14277

When you annotate your beans with @SessionScoped in Portlet application it is mapped to something as "Portlet Instance Session". This means that this bean will live in session of that portlet, and each portlet has its own session. There is something called "Global Session" which is session shared across all portlets, but as far as I know there is not such annotation in JSF.

Upvotes: 2

Related Questions