如何正确获取liferay portlet中页面的组织方式?
我尝试过:
公司。不是一个组织,而是一个门户实例。
组。是当前用户的组,而不是当前页面的组。
更新
我在 portlet 类的 doView
方法中。我知道如何将我在这里获得的任何内容向上传递到 JSP,以便可以通过 EL/JSTL 访问。
更新2
group.getOrganizationId()
始终返回零。
更新3
我用这段代码来准备变量
private void storeVariables(RenderRequest renderRequest) {
PortletPreferences prefs = renderRequest.getPreferences();
String image_id = (String) prefs.getValue("image_id", "communicator");
ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
Company company = themeDisplay.getCompany();
Group group = themeDisplay.getScopeGroup();
log.info("group = {}", group);
long organizationId = group.getOrganizationId();
log.info("organizationId = {}", organizationId);
PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
String contextPath = renderRequest.getContextPath();
if( !contextPath.endsWith("/") ) {
contextPath = contextPath + "/";
}
renderRequest.setAttribute("images", images);
renderRequest.setAttribute("image", images.get(image_id));
renderRequest.setAttribute("image_id", image_id);
renderRequest.setAttribute("themeDisplay", themeDisplay);
renderRequest.setAttribute("portletDisplay", portletDisplay);
renderRequest.setAttribute("contextPath", contextPath);
}
更新3
JSP 中的以下代码返回空字符串
<!-- scopeGroupId = <c:out value="${scopeGroupId}"/> -->
最佳答案
组是内容和页面的容器,是网站、布局范围、暂存等的内部实体。
在 Liferay 6.1 中,站点(在以前的版本中称为社区)可以与组织关联。这取决于您所在的位置(在 JSP 中、在 portlet 类中等),但是,如果您有代表当前组的实体,则可以编写如下内容:
Organization organization = null;
if (group.isOrganization()) {
organization = OrganizationLocalServiceUtil.getOrganization(group.getOrganizationId());
}
希望有帮助。询问您是否需要帮助来检索 Group 对象...
关于java - 如何在liferay portlet中获取页面的组织方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16285590/