7 Replies Latest reply on May 8, 2013 1:29 PM by kenfinni

    Session parameters + more same portlets in one portal page

    mbasovni

      Hello,

       

      I have one qustion. Do you know how to ensure that for each portlet and user it will be one backing bean instance with session scope?

       

      e.g. I have backing bean UserController with session scope and attribute user. When I change user of one portlet, the user in second portlet will change too, but I do not want  this!

       

      I tried to use anotations @ManagedBean + @ViewScoped instead of @Named + @SessionScoped, but now user attribute is empty...

       

      Can you help me how this "multi-portlet session" problem solve?

       

      Thank you.

        • 1. Re: Session parameters + more same portlets in one portal page
          kenfinni

          Martin,

           

          Just to clarify, if you're using JSF managed beans then @ManagedBean should be present on the bean whether you use @ViewScoped or @SessionScoped.

           

          Another thing to check is to make sure that the @SessionScoped annotation being used is the JSF one and not the CDI one.

           

          Can you elaborate on what you mean by "change the user of one portlet"? Does that mean log out and log in with a different user account?

          • 2. Re: Session parameters + more same portlets in one portal page
            mbasovni

            I was using:

             

            import javax.enterprise.context.SessionScoped + import javax.inject.Named

             

            and session bean attributes were overwriting... Portlets were saving to APPLICATION SESSION apparently...

             

            Now I tried:

            javax.faces.bean.SessionScoped + javax.faces.bean.ManagedBean

             

            and it seams it works!

             

            Just for assurance:

            Now portlet bridge will save session beans attributes to PORTLET SESSION? It is my target!!! My portal will contain several same portlets and they must have different session scopes!

             

            It is ok if i am using anotation injection @javax.inject.Inject. Or would be better to use @javax.ejb.EJB?

            • 3. Re: Session parameters + more same portlets in one portal page
              kenfinni

              The SessionScoped you were using is the CDI one, which without CDI being enabled would have no meaning to JSF.

               

              If a JSF Managed Bean is annotated with @SessionScoped and @ManagedBean, then that will be session scoped to JSF, they will not be available as attributes on the Portlet Session.

               

              So each portlet in the portal needs to have different session scope data for the same user? Or do you mean that the same portlet will contain different session data for different user sessions? The former is not possible, but the latter is.

               

              javax.inject.Inject would only apply if you're using CDI. To perform injection with JSF, take a look at: http://www.mkyong.com/jsf2/injecting-managed-beans-in-jsf-2-0/

              • 4. Re: Session parameters + more same portlets in one portal page
                mbasovni

                Yes I need to have portlets which session will be both unique for each user and each portlet instance (of same portlet) will have different session scope (PORTLET SESSION SCOPE). Is it possible? No i am mapping session variables to portlet session manually:

                 

                        Object objSession = FacesContext.getCurrentInstance().getExternalContext().getSession(false);
                
                        if (objSession instanceof PortletSession) {
                            PortletSession portalSession = (PortletSession) objSession;
                            portalSession.setAttribute(attrName, object, PortletSession.PORTLET_SCOPE);
                        }
                
                • 5. Re: Session parameters + more same portlets in one portal page
                  kenfinni

                  If you're setting attributes into the PORTLET_SCOPE of the PortletSession, as above, then those attributes will be unique to a user and a portlet instance (so the same portlet used multiple times on a portal page will see different values).

                   

                  So it sounds like it should do what you want

                  • 6. Re: Session parameters + more same portlets in one portal page
                    mbasovni

                    Yes! This is what I want. I works for me now. I only want to know if there is a  "better practise" for this problem => "more instances of one portlet on one portal page for one user session"

                     

                    Thank you very much!

                    • 7. Re: Session parameters + more same portlets in one portal page
                      kenfinni

                      To my knowledge there isn't another way to deal with that situation