简体   繁体   中英

get user group description and name in liferay

I want to get the user group description as well the name of logged-in user in portlet. I am able to get the logged-in user object using:

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

Please help me out with how to get the logged-in user's group. These user groups are coming from ldap and mapped in liferay DB UserGroup.

Thanks in advance.

As you have the user object, you can get full name of user by using

user.getFullName()

for getting the user group description, call the following method, which will give you the list of Groups. which belongs to user.

List <Group> grpList = GroupLocalServiceUtil.getUserGroups(userId);

Iterate the list to get the groupId's. Pass group Id to following method.

Group grp = GroupLocalServiceUtil.getGroup(groupId)

You can get group Description using

String grpDisc = grp.getDescription();

Hope this is what you are looking for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM