3
votes

Problem

When showing a portlet (say test-portlet) in pop-up through a link in another portlet (say abc-portlet), the scopeGroupId shown in the test-portlet is always the groupId and not the page-scope-id or scopeGroupId which is configured for abc-portlet.

More details follow, if the problem is not clear.

Basically what I have done is what is mentioned in this answer. Will give the brief below.

What we have done

  1. Created a custom portlet - test-portlet
  2. Have made that portlet scopeable <scopeable>true</scopeable>
  3. Have also added - <add-default-resource>true</add-default-resource>
  4. This works fine as intended even with page-scope
  5. We have another portlet - abc-portlet
  6. same configuration as test-portlet
  7. this portlet also works fine

What we are doing and what is happening

  1. We are calling test-portlet in a pop-up from abc-portlet
  2. This works
  3. Now we change the scope of abc-portlet to page (say Home)
  4. Now when we access the test-portlet the scope shown in test-portlet is still Liferay (i.e. the Guest group) and not Home as set in abc-portlet.

Question

  1. Is there any more configuration so that test-portlet can pick-up the scopeGroupId same as abc-portlet
  2. Is there anything possible I can change in the code which can tell the test-portlet to use the scopeGroupId of abc-portlet i.e. make test-portlet aware of the scope of abc-portlet?

Any pointers in the direction will be of great help.

Environment: Liferay 6.2 EE bundled with Tomcat

Thanks

Note: Have also cross posted this on Liferay Developer Forum.

1

1 Answers

1
votes

So after some searching finally found out how liferay does it. The hint came from the source code in ServicePreAction:

if (!group.isControlPanel()) {
    doAsGroupId = 0;
}

Liferay uses this functionality in Related Assets for adding a blog, wiki, document, folder etc while adding or editing an asset, so checked the JSP /html/portlet/asset_browser/toolbar.jsp to see how the URL is made.

Liferay's steps are similar to what I wanted to do:

  1. Give a link to open the asset portlet (for eg: Blog) to add an entry.
  2. The pop-up which opens has the same scopeGroupId as that of the underlying portlet (for eg: Documents and Media)

One would think that the attribute doAsGroupId is just fit for this scenario. Yes it is essential but alone it does not suffice and surprisingly the other attribute which is essential is plid. By default plid will be the current page/layout the user is on and the URL would be made with respect to the current page but this default value does not help.

The plid needs to be set to the plid of Control Panel!

Here is the sample renderURL we write in the abc-portlet to open test-portlet in the pop-up, notice the attributes doAsGroupId="<%=scopeGroupId %>" and plid="<%=controlPanelPlid %>" of <liferay-portlet:renderURL:

<%
long controlPanelPlid = PortalUtil.getControlPanelPlid(company.getCompanyId());
%>

<liferay-portlet:renderURL var="testPortletURL" portletName="test_WAR_testportlet" windowState="<%=LiferayWindowState.POP_UP.toString() %>"
        doAsGroupId="<%=scopeGroupId %>" plid="<%=controlPanelPlid %>" refererPlid="<%=plid %>">
    <liferay-portlet:param name="referringPortletResource" value="abc_WAR_abcportlet" />
</liferay-portlet:renderURL>

<%
String testPortletURLJavascript = "javascript:Liferay.Util.openWindow({dialog: {destroyOnHide: true}, id: 'test', title: 'Test Portlet View', uri: '" + HtmlUtil.escapeJS(testPortletURL) + "'});";
%>

<h4><a href="<%=testPortletURLJavascript%>">Click here to open test portlet in pop-up</a></h4>

Wonder why liferay thought of using plid="<%=controlPanelPlid %>" instead of just the doAsGroupId which seems pretty straight-forward.

Note: I also discovered that if we use plid="<%=controlPanelPlid %>" we don't need to have <add-default-resource>true</add-default-resource> in liferay-portlet.xml which is essential if the resource needs to be dynamically added.

Hope this helps somebody.