Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Accessing the user from a liferay portlet

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 638
    Comment on it

    Hello Guys

    Liferay is an EMS to develop java based web application and it's have portlets to write business logics.

    Liferay provide inbuilt login and other portlets, so now we need to use functionality of them in our custom portlets.

    For better understating see below example in which accessing user details or info in our custom portlets.

    Following code help you to getting current or login user details

    ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute(WebKeys.THEME_DISPLAY);
    
    User user = themeDisplay.getRealUser(); // it gives you the actual Logged in User
    
    long userId = user.getUserId();
    String userName = user.getEmailAddress();
    
    //you can also use
     User user = themeDisplay.getUser(); // this would fetch the User you are impersonating 
    
    long userId = user.getUserId();
    String userName = user.getEmailAddress();
    

    Following code help you to getting user details by userId

    User user = UserLocalServiceUtil.getUser(userId);
    long userId = user.getUserId();
    String userName = user.getEmailAddress();
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: