我正在使用Vaadin在Liferay 6中开发门户,并且需要获取门户所在社区的ID。应该如何实现?
Liferay中没有Community实体,它只是另一种类型的组(请参见GroupConstants
)。
如果您可以访问ThemeDisplay
对象,我认为这将为您提供社区的ID。
long id = themeDisplay.getLayout().getGroupId();
在 struts action 中,您可以通过以下方式获取 ThemeDisplay:
ThemeDisplay themeDisplay =
(ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
其中request
可以是RenderRequest
或ActionRequest
。
对于那些在 Liferay portlets 中使用 Spring MVC 的用户,将以下内容添加到 ControllerClass 中
@ModelAttribute("tD")
public String getThemeDisplay(RenderRequest req) {
ThemeDisplay themeDisplay = (ThemeDisplay) req.getAttribute(WebKeys.THEME_DISPLAY);
return themeDisplay.getPathThemeImages();
}
<img src="${tD}/[image-path] />