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)