How to find portlets added on a particular page in Liferay?

后端 未结 1 1245
眼角桃花
眼角桃花 2020-12-17 15:00

How can I find which portlets are added on a particular Liferay page?

For Example:
I have three pages: Welcome, Wiki and Search.

相关标签:
1条回答
  • 2020-12-17 15:25

    I have found two ways to do this:

    1. If you want to find the portlets on the same page in which your portlet is added then, you can make use of themeDisplay object available to your portlet or JSP:

      // In JSP
      List<String> portletIdList = themeDisplay.getLayoutTypePortlet().getPortletIds();
      
      // In portlet class
      ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);
      List<String> portletIdList = themeDisplay.getLayoutTypePortlet().getPortletIds();
      
    2. If you want to find the portlets on some different page, then you should know three things viz; friendly-url, groupId and whether this page is a public-page or private-page of the Site (or Community), so here is the code:

      // 101543 is the SiteId, if it is a public-page then "false" and "/search" is the friendlyURL
      LayoutTypePortlet layoutTypePortlet = LayoutTypePortletFactoryUtil.create(LayoutLocalServiceUtil.getFriendlyURLLayout(101543, false, "/search"));
      List<String> portletIdList = layoutTypePortlet.getPortletIds();
      

    The portletIdList contains the portletIds complete with their instanceIds. So now from the list you can just filter out the iframe-portlet on the /search page by using com.liferay.portal.util.PortletKeys.IFRAME and you will get something like 48_INSTANCE_rPv9.

    0 讨论(0)
提交回复
热议问题