Search code examples
javaliferayportlet

How to obtain page's organization in liferay portlet?


How to obtain page's organization in liferay portlet correctly?

I tried:

Company. Is not an organization, but a portal instance.

Group. Is group of current user, not of current page.

UPDATE

I am in the portlet class' doView method. I know how to pass anything I can obtain here upwards to JSP to be accessible via EL/JSTL.

UPDATE 2

group.getOrganizationId() always returns zero.

UPDATE 3

This code I use to prepare variables

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);


}

UPDATE 3

The following code in JSP returns empty string

<!-- scopeGroupId = <c:out value="${scopeGroupId}"/> -->

Solution

  • A group is a container of content and pages, and it's the internal entity for sites, layout scopes, staging and so on.

    In Liferay 6.1, a site (which was called community in previous versions) can be associated to an organization. It depends on where you are (in a JSP, in the portlet class, etc.), but, if you have the entity representing the current Group, you can write something like this:

    Organization organization = null;
    
    if (group.isOrganization()) {
        organization = OrganizationLocalServiceUtil.getOrganization(group.getOrganizationId());
    }
    

    Hope it helps. Ask if you need help in order to retrieve the Group object...