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
.
Every portlet WAR must have one portlet. xml file in the WEB-INF directory of the web application.
RE: How to get current portlet's name? portletDisplay is a variable that will be already available in your JSP if you've included Liferay's init. jsp or have added yourself an invocation to the theme:defineObjects tag. Gaspare Provenzano, modified 15 Years ago.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With