7 Replies Latest reply on Oct 19, 2007 10:53 AM by tl le

    How to set and get Portal session

    tl le Newbie

      Hello,
      Is there a way to set portal session so that all of the portlets inside will recieve the same session? I have a class that retrieves some things from the database and I want to distribute those data to all of the portlets within the portal. The best way I can think of is to distribute those data through portal session and don't really know how to do this so far. Is there any example or documents that I should read about setting data through portal sesison and how to get those data from a portlet?
      I am using jboss portal 2.6.1
      Your help is appreciated

      Thanks,

      SGM

        • 1. Re: How to set and get Portal session
          Andi Newbie

          request.getPortletSession().setAttribute("xxx", xxx, PortletSession.APPLICATION_SCOPE);

          i really advise against it though. as the idea is that portlets are spoused to be independent units.

          • 2. Re: How to set and get Portal session
            tl le Newbie

            Hi,
            Thanks for the response. The solution you provided only works with portlets within a portal project. If I have another portlet project deployed in jboss server (hot deploy) then this won't work (at least for me)
            What I would really like to find out is how to distribute a value/object to all of the portlets deployed within the portal (they can be hot deployed, meaning that they are seperate portlet projects)
            For example, I have a string value say String str = "my value". How do I distribute this value to all portlets from the portal scope when the portlets need this value without having the portlets to connect to database to get this value?

            Thanks,

            SGM

            • 3. Re: How to set and get Portal session
              Andi Newbie

              well i dont think its just a portlet problem then. if you deploy 2 wars warA can not see Warb's session without doing some kind of call back. there is always application scope, but thats worse then using the session scope.

              that said you could probably create a singelton class to hold the values, shove it into the application scope and have you portlets grab it from there.

              i personally would put all the portlets that need to share the same session info into one war and let them all deploy together. on our current project we dont even use session scoped jsf beans, we pass it all along the request, or make a call to the db using request.getRemoteUser() as the parameter to the stored procedure.

              • 4. Re: How to set and get Portal session
                Thad West Newbie

                Basically you want to cache DB retrievals because you don't want to do them again?

                If so, it sounds like a job for your persistence framework (like caching in hibernate).

                Or you could do your own caching with something like JCS --> http://jakarta.apache.org/jcs/. They support many different types of caches, even caches for a scaled environment.

                • 5. Re: How to set and get Portal session
                  tl le Newbie

                  Thanks for your responses. The string value is just one of the things we want to pass to the portlets. I wonder if you have done anything to user's roles retrieving? That means that if you have a login page in the portal, after you log in, Jboss knows how to map that user's role to appropriate portlets. I wonder if JBoss ever exposes that role throughout its scope? If it does, do you know the name of that variable? (like PortletSession.APPLICATION_SCOPE) or is there a way to get the user's role without doing a JNDI lookup through Hibernate to the database to get the role?

                  Thanks,

                  SGM

                  • 6. Re: How to set and get Portal session
                    Andi Newbie

                    their are a few things in http request for that.

                    isUserInRole("String"); which returns a boolean or

                    getUserPrincipal() which returns a Principle

                    • 7. Re: How to set and get Portal session
                      tl le Newbie

                      Hi,
                      The isUserInRole("String") always returns false for the default roles in jboss which are "Admin" and "Users" or whatever default roles comes with jboss.
                      I don't know if there are any configurations that I should do first. Searching in this forum for this question is hard since there are lots of question related to this method. I read the documentation and saw there is an API for portal session called PortalSession. Have you ever tried to stored objects in this sesison? If yes, how did you do that?

                      Thanks,

                      SGM