掲示板

Retrieving user list in portlet

16年前 に Ionut Maxim Margelatu によって更新されました。

Retrieving user list in portlet

New Member 投稿: 1 参加年月日: 08/03/27 最新の投稿
Hello,

I'm currently developing a couple of portlets on top of Liferay ; one of the portlets is a sort of "admin" portlet, which needs to retrieve the list of users of the portal.

Now I tried the following solution :


...
Map userInfoMap = (Map) ((PortletRequest) FacesContext
				.getCurrentInstance().getExternalContext().getRequest())
				.getAttribute(PortletRequest.USER_INFO);

String userId = (String) userInfoMap.get("liferay.user.id");
User user = UserLocalServiceUtil.getUserById(Long.parseLong(userId));

List users = UserLocalServiceUtil.getGroupUsers(user.getGroup().getGroupId());

...


Now it seemed very easy : I have to get the current user, then to retrieve the group he's a part of and then retrieve all the users from that group. This should at least return the users belonging to the same group as the current user. However the code doesn't work as expected. While the current user is correctly retrieved, along with a non-null groupId, the users list comes up empty. The group contains at least one user, the current one, so the users list should have at least one element.

Could someone please point me to the right solution ?

Thanks,
Ionut
thumbnail
16年前 に Wilson Man によって更新されました。

RE: Retrieving user list in portlet

Liferay Master 投稿: 581 参加年月日: 06/06/21 最新の投稿
can you validate that the groupId you're getting from user is the right groupId? I don't have time to do a thorough research just yet, but i'm guessing that the groupId might be an ID of his/her personal community/group.
thumbnail
15年前 に Ron Bense によって更新されました。

RE: Retrieving user list in portlet

Regular Member 投稿: 117 参加年月日: 07/08/23 最新の投稿
You might try getting the companyId and retrieving all the users of that company, or step through the organizations/locations he's a member of and create lists/hashes of the users retrieved for those.

Depending upon what version of Liferay you're using, users can be members of more than one organization/location(locations are organizations).

You'll need to be more descriptive of what you're trying to accomplish if this doesn't help steer you in the right direction.

Good luck!
thumbnail
14年前 に Lucas Roberto Thomaz によって更新されました。

RE: Retrieving user list in portlet

Regular Member 投稿: 138 参加年月日: 09/07/21 最新の投稿
I need retry a list of users.

I tryed with this way as you said and doesnot work.

I'm using sdk in version 5.2.3

Can someone help?

Thanks in advance.

Lucas
13年前 に Wim van der Vegt によって更新されました。

RE: Retrieving user list in portlet

New Member 投稿: 7 参加年月日: 10/07/08 最新の投稿
Here some code that seems to work from inside an action:


	public String btnCopyUsersAction() {
		traceMethod();

		PortletRequest request = (PortletRequest) FacesContext
				.getCurrentInstance().getExternalContext().getRequest();

		if (request != null) {
			ThemeDisplay themeDisplay = (ThemeDisplay) request
					.getAttribute(WebKeys.THEME_DISPLAY);

			if (themeDisplay != null) {
				System.out.println("Portlet Scope GroupId "
						+ themeDisplay.getScopeGroupId());
				try {
					Group grp = GroupLocalServiceUtil.getGroup(themeDisplay
							.getScopeGroupId());

					if (grp != null) {
						List<user> users = UserLocalServiceUtil
								.getGroupUsers(grp.getGroupId());
						if (users != null) {
							for (User user : users) {																	System.out.println(((Long) user.getUserId())
													.toString()
													+ "="
													+ user.getFullName());

								}
							}
						} else {
							setFeedback("Error: Could not obtain User List ");
						}
					} else {
						setFeedback("Error: Could not obtain Group Object");
					}
				} catch (PortalException e) {
					setFeedback("Error: " + e.getMessage());
					e.printStackTrace();
				} catch (SystemException e) {
					setFeedback("Error: " + e.getMessage());
					e.printStackTrace();
				}
			} else {
				setFeedback("Error: Could not obtain ThemeDisplay Object");
			}
		} else {
			setFeedback("Error: Could not obtain PortletRequest Object");
		}

		return null;
	}</user>