Search This Blog

Tuesday, July 16, 2013

How to get the current logged in user in liferay

There are more than one way to do this. Let's look at some of the options available.
  1. User user = (User) request.getAttribute(WebKeys.USER);
    The User class is the Liferay's model User class.

  2. ThemeDisplay td  = (ThemeDisplay) request.getAttribute( WebKeys.THEME_DISPLAY );
    User user = td.getUser();


    This ' ThemeDisplay 'class can be used to get various information about the portal page,user and theme. Classes ThemeDisplay, User and WebKeys are available in portal-service.jar

  3. User currentUser = PortalUtil.getUser( request );

    The 'PortalUtil' has various utility functions , which come handy during Liferay Programming. This is also a part of the Portal-service.jar.

  4. LiferayFacesContext liferayFacesContext = LiferayFacesContext.getInstance();
    User currentUser=liferayFacesContext.getUser();


    The class 'PortalFacesContext' has been renamed to 'LiferayFacesContext'.This class exists in order to assist with migrating old JSF 1.2 based projects from the legacy PortletFaces-Tools project to the new LiferayFaces project.

    Hope It helps you in your portal programming. Happy Coding :)


No comments:

Post a Comment

My Blog List