How can I get current group id (or community id) in liferay (java)?

Pat Guy picture Pat Guy · Mar 24, 2011 · Viewed 21k times · Source

I'm developing portlet with Vaadin in Liferay 6 and I need to get the ID of the community where the portlet is located. How is it done?

Answer

blank picture blank · Mar 24, 2011

There is no Community entity in Liferay, it's just another kind of group (see GroupConstants)

If you have access to a ThemeDisplay object I think this will give you the Id of the community

long id = themeDisplay.getLayout().getGroupId();

In a struts action you can get ThemeDisplay like this:

ThemeDisplay themeDisplay = 
     (ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);

where request can be a RenderRequest or an ActionRequest.