Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 642
Prakash K Avatar asked Aug 06 '12 11:08

Prakash K


People also ask

Where is portlet XML?

Every portlet WAR must have one portlet. xml file in the WEB-INF directory of the web application.

How do you get a portlet name in Liferay?

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.


1 Answers

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.

like image 156
Prakash K Avatar answered Jan 03 '23 01:01

Prakash K