3 Replies Latest reply on Nov 24, 2010 11:04 PM by Rich Raposa

    How can I get the user information in a GateIn portlet?

    Jozsef Szalai Newbie

      Hi,

       

      I tried to write a simple portlet, which shows me the information (name, username, e-mail address, etc.) of the currently logged in user. I found this in the GateIn documentation, but I don't know how can I use it (which packages/classes do I need to import, and which .jar files do I have to add to the webproject properties).

       

      Can anybody show me a whole .java file, which works?

       

      Thanks a lot,

      Jozsef

        • 1. Re: How can I get the user information in a GateIn portlet?
          Benjamin Seyinbour Newbie

          Hello Jozsef Szalai,

           

          If I were you, next time, I would first search this forum or the GateIn doc or both for answers before posting a question – then you wouldn't have to wait. Anyway here is some information:

           

          import org.exoplatform.container.PortalContainer;

          import org.exoplatform.portal.application.PortalRequestContext;

          import org.exoplatform.services.organization.OrganizationService;

          import org.exoplatform.services.organization.User;

           

          //  Method to retrieve User details

           

          User portletUser = null;

          PortalRequestContext portalRequestContext = PortalRequestContext.getCurrentInstance();

           

          // Get the id of the current user logged in

          String remoteUserName = portalRequestContext.getRemoteUser();

          OrganizationService organizationService = (OrganizationService)PortalContainer.getInstance().getComponentInstanceOfType(

          OrganizationService.class);

           

          if (remoteUserName != null) {

          portletUser = organizationService.getUserHandler().findUserByName(remoteUserName);

          }

           

           

          You would then find the user details you need in the  portletUser. See  org.exoplatform.services.organization.User.

          There also another way of doing it which the GateIn doc will tell you.

          • 2. Re: How can I get the user information in a GateIn portlet?
            Jozsef Szalai Newbie

            Hello Benjamin,

             

            Thanks for your hints it helped a lot, but I still got a null pointer exeption at the PortalRequestContext portalRequestContext = PortalRequestContext.getCurrentInstance(); line. I attached the error log, and the java and jsp files.

             

            Do you have any idea?

             

            Thanks,

            Jozsef

            • 3. Re: How can I get the user information in a GateIn portlet?
              Rich Raposa Novice

              This is an old post, but it needs correcting. The method:

               

              PortalRequestContext.getCurrentInstance()
              

               

              appears to not be in the API anymore. I found an alternate way to obtain a PortalRequestContext instance:

               

              PortalRequestContext context = Util.getPortalRequestContext();
              

               

              where Util is in the org.exoplatform.portal.webui.util package.

               

              This needs to be fixed in the Reference Guide as well. The remainder of the code works fine. FWIW, if you're using Eclipse/JBDS you need to add the following JAR files to your build path:

              gatein.ear/lib/exo.core.componenet.organization.api-xxx.jar

              gaetin.ear/lib/exo.kernel.container-xxx.jar

              gatein.ear/lib/exo.portal.webui.portal-5.1.x-epp.jar

               

              -Rich