Tribune

Home » Liferay Portal » English » 3. Development

Vista Combinata Vista Piatta Vista ad Albero
Discussioni [ Precedente | Successivo ]
toggle
Ken Driscoll
Get User Group of User?
16 luglio 2012 13.56
Risposta

Ken Driscoll

Punteggio: Junior Member

Messaggi: 57

Data di Iscrizione: 2 luglio 2012

Messaggi recenti

I set/get the User Group of a Liferay user. As an admin, I assigned a user to a user group. I've even check the user's profile to make sure it was assigned to him, and it was. Now in my portlet, I am able to get the user no problem, but the following method is saying that the user isn't assigned to a User Group...

1List<Group> groups = GroupLocalServiceUtil.getUserGroups(user.getUserId());
2System.out.println("Group count: "+groups.size());


Which prints out:
1Group count: 0


I'm not sure what I'm doing wrong...it may be the way I'm assigning the user to the group, or the way I'm retrieving the group. Any assistance would be greatly appreciated.
Hitoshi Ozawa
RE: Get User Group of User?
16 luglio 2012 14.22
Risposta

Hitoshi Ozawa

Punteggio: Liferay Legend

Messaggi: 7949

Data di Iscrizione: 23 marzo 2010

Messaggi recenti

You're looking at the wrong method.

To get group which a user is assigned to, just get the user and just doe getGroups()

User user= themeDisplay.getUser();
List<Group> groups = user.getGroups();
Ken Driscoll
RE: Get User Group of User?
16 luglio 2012 15.17
Risposta

Ken Driscoll

Punteggio: Junior Member

Messaggi: 57

Data di Iscrizione: 2 luglio 2012

Messaggi recenti

Hitoshi Ozawa:
You're looking at the wrong method.

To get group which a user is assigned to, just get the user and just doe getGroups()

User user= themeDisplay.getUser();
List<Group> groups = user.getGroups();


I've tried this and am having the same problem. That list is also empty. Any other ideas?
Tejas Kanani
RE: Get User Group of User?
16 luglio 2012 21.34
Risposta

Tejas Kanani

Punteggio: Liferay Master

Messaggi: 655

Data di Iscrizione: 6 gennaio 2009

Messaggi recenti

Hi Ken,

You can get all the userGroup assigned to particular user using getUserUserGroups method of UserGroupLocalServiceUtil.

1List<UserGroup> userGroups = UserGroupLocalServiceUtil.getUserUserGroups(themeDisplay.getUserId());


HTH.

Regards,
Tejas
Sachin Mane
RE: Get User Group of User?
16 luglio 2012 21.45
Risposta

Sachin Mane

Punteggio: Junior Member

Messaggi: 76

Data di Iscrizione: 9 aprile 2012

Messaggi recenti

GroupLocalServiceUtil.getGroups () will return you the logical group of the user, group id of the communities, organization that user belongs to.

GroupLocalServiceUtil.getUserGroups () will return the user groups - which is the grouping of users done for role assignment/authorization purpose.
Ken Driscoll
RE: Get User Group of User?
17 luglio 2012 12.17
Risposta

Ken Driscoll

Punteggio: Junior Member

Messaggi: 57

Data di Iscrizione: 2 luglio 2012

Messaggi recenti

I've tried all of these methods with no success. Perhaps I'm not setting the user group correctly? Even though it shows up in the profile...what am I doing wrong?
Hitoshi Ozawa
RE: Get User Group of User?
17 luglio 2012 16.01
Risposta

Hitoshi Ozawa

Punteggio: Liferay Legend

Messaggi: 7949

Data di Iscrizione: 23 marzo 2010

Messaggi recenti

Sorry, you wanted user groups instead of just groups. Tested and worked properly for me with Liferay 6.1.0 CE

User user3 = themeDisplay.getUser();
long[] groups = user3.getUserGroupIds();
System.out.println("groups.size:" + groups.length);
System.out.println("userGroup:" + UserGroupLocalServiceUtil.getUserGroup(groups[0]).getName());
Ken Driscoll
RE: Get User Group of User?
18 luglio 2012 7.13
Risposta

Ken Driscoll

Punteggio: Junior Member

Messaggi: 57

Data di Iscrizione: 2 luglio 2012

Messaggi recenti

And we have a winner! Thank you so much for your time Hitoshi.