Thursday, June 12, 2014

[Liferay] Get all the sites in Liferay

Its time I start posting about Liferay.. :)

Most of the times we need very small things.. code that can help us getting data from liferay.. its all there already, but we are not aware most often..

I had to load all groups/sites in a dropdown and then select one to extract some content from the document library of that group. So to make it easier, and clean It was better to provide a list of all sites to Admin and let Admin decide which one to be selected.

To get all the groups we can simply use.
List<Group> groups = GroupLocalServiceUtil.getGroups(0, GroupLocalServiceUtil.getGroupsCount());

But to get only sites we need.. to use search method.
List<Group> groups = GroupLocalServiceUtil.search(PortalUtil.getCompanyId(renderRequest), null, null,null, QueryUtil.ALL_POS, QueryUtil.ALL_POS);

Imports are..
com.liferay.portal.kernel.dao.orm.QueryUtil
com.liferay.portal.util.PortalUtil
com.liferay.portal.model.Group
com.liferay.portal.service.GroupLocalServiceUtil

Thats it.. :)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.