Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Lokesh Kumar N
Need to get information of the Community in a portlet
March 5, 2013 1:34 AM
Answer

Lokesh Kumar N

Rank: New Member

Posts: 1

Join Date: August 14, 2012

Recent Posts

Hi,

Let's say I have added a portlet inside a community. From the portlet I need the information of the community such as the community name, community owner etc...

How to get these community information from the portlet. Any suggestions here would be helpful

Thanks,
Lokesh
Juhi Kumari
RE: Need to get information of the Community in a portlet
March 5, 2013 4:13 AM
Answer

Juhi Kumari

Rank: Expert

Posts: 347

Join Date: December 12, 2011

Recent Posts

Hi,
You can get information of a community like this
 1List<Group> groups = GroupLocalServiceUtil.getGroups(QueryUtil.ALL_POS,QueryUtil.ALL_POS);
 2String name;
 3long userId;
 4User user;
 5for(Group group : groups){
 6        if(group.isCommunity()){
 7            name = group.getName();
 8            userId = group.getCreatorUserId();
 9            user = UserLocalServiceUtil.getUser(userId);
10            System.out.println("Community Name >>> "+name+" Owner Name >>> "+user.getFullName());
11        }
12    }


Regards
Juhi
Felix J Christy
RE: Need to get information of the Community in a portlet
March 5, 2013 6:19 AM
Answer

Felix J Christy

Rank: Regular Member

Posts: 111

Join Date: August 25, 2009

Recent Posts

Hi,

To access the current community in which the portlet is deployed, you can call the PortalUtil.getScopeGroupId(portletRequest) method. After getting the groupId, just get the group name using

GroupLocalServiceUtil.getGroup(long groupId);.

Once you get the Group object, just take the name and owner info.


Thanks,
Felix