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

I am developing a portlet with Vaadin in Liferay 6, and I need to get the ID of the community in which the portlet is located. How it's done?

+4
source share
2 answers

There is no community object in Liferay, it's just a different type of group (see GroupConstants )

If you have access to ThemeDisplay object, I think this will give you a community id

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

In struts action, you can get ThemeDisplay as follows:

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

where request can be RenderRequest or ActionRequest .

+10
source

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

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

To reference an image in jsp just add

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

Hope this helps.

+1
source

Source: https://habr.com/ru/post/1345093/


All Articles