Pat Guy
Pat Guy

Reputation: 61

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

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?

Upvotes: 6

Views: 23879

Answers (2)

Pascal
Pascal

Reputation: 9

For those of you who use Spring MVC as Liferay portlets add this to the ControllerClass

     @ModelAttribute("tD")
    public String getThemeDisplay(RenderRequest req) {
        ThemeDisplay themeDisplay = (ThemeDisplay) req.getAttribute(WebKeys.THEME_DISPLAY);
        return themeDisplay.getPathThemeImages();
    }

To refere to an image in jsp just add

<img src="${tD}/[image-path] />

Upvotes: 0

blank
blank

Reputation: 18170

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.

Upvotes: 11

Related Questions