How can I find which portlets are added on a particular Liferay page?
For Example:
I have three pages: Welcome, Wiki and Search.
Now all these pages have portlets added on them and some of them are instanceable portlets (like web-content display and iframe portlets).
Now I want to pass some information in the form of request parameters to the iframe-portlet
on the Search page
from the Welcome page
.
I have found two ways to do this:
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();
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
.