Make the dynamically added portlet have the same scopeGroupId as the calling portlet

Problem

When displaying a portlet (say a test portlet) in a popup through another portlet (for example, abc-portlet), the scopeGroupId

one shown in the test portlet is always the groupId, not the page scope -id or scopeGroupId that is configured for abc-portlet.

See below for details if the problem is not clear.

Basically what I have done is what is mentioned in this. Below is a brief description.

What have we done

  • Created own portlet - test portlet
  • Made this portlet available <scopeable>true</scopeable>

  • Added - <add-default-resource>true</add-default-resource>

  • This works great as intended even with page scale
  • We have another portlet - abc-portlet
  • same configuration as test portlet
  • this portlet works fine too

What we do and what happens

  • We call the test portlet in the popup from abc-portlet
  • It works
  • Now we will change the scope of abc-portlet to page (like Home)
  • Now when we access the test portlet, the area shown in the test portlet is still Liferay (i.e. the guest group), not Home as set in abc-portlet.

Question

  • Is there any more configuration so the test portlet can capture the scopeGroupId just like abc-portlet
  • Is there anything possible that I can change in the code that can tell the test portlet to use the scopeGroupId from abc-portlet, i.e. to make the test portlet aware of the scope of the abbreviation?

Any pointers in the direction would be very helpful.

Environment: Liferay 6.2 EE bundled with Tomcat

thank

Note. ... Also cross-posted this on the Liferay Developer Forum .

+3


source to share


1 answer


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

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

      

Liferay uses this functionality Related Assets

to add a blog, wiki, document, folder, etc. when adding or editing an asset, so checked the JSP /html/portlet/asset_browser/toolbar.jsp

to see how the url is generated.

Liferay steps are similar to what I wanted to do:

  • Provide a link to open an object portlet (eg blog) to add an entry.
  • The popup that opens has the same scopeGroupId as the base portlet (for example, documents and media).

You might think that the attribute doAsGroupId

is only suitable for this scenario. Yes, it is important, but it alone is not enough and it is surprising that another attribute that is important is plid

. The default plid

will be the current page / layout where the user is enabled and the url will be made relative to the current page, but this default doesn't help.



The parameter plid

must be set to a value Control Panel

!

Here is an example renderURL we write in abc-portlet to open the test portlet in a popup, notice the attributes doAsGroupId="<%=scopeGroupId %>" and plid="<%=controlPanelPlid %>"

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

      

I wonder why liferay was thinking about using it plid="<%=controlPanelPlid %>"

instead of just doAsGroupId

, which seems pretty straight forward.

Note. ... I also found 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 someone.

+1


source







All Articles