Thursday 7 June 2012

How to link portlets located on different pages in Liferay Portal

Following with the IPC (inter portlet communication), let's go with an example that explains how to create a link in one portlet that points to another portlet located on a different page (editor's note: wow!! - editor's hint: portlets are not pages)

To do this we have to use the tlds :

liferay-portlet:renderURL
liferay-portlet:actionURL


and the concepts of

plid: referenced page layout id
portletName: referenced portlet name

The renderURL and the actionURL are tags provided by Liferay that extend the standard tlds. Note: this kind of communication is not part of the standard of the portlets JSR168 and JSR286.
  • The plid is the id of the page where we deploy one portlet, we can use LayOutLocalService to seek the id, or query it in the database directly.
  • The portletName is the identifier of the portlet and is part of the deployment descriptor of the portlet. This id is composed by portletId+_WAR_+thenameofwarthatencapsulatestheportlet and optionally the _INSTANCE_ if the portlet is instanciable.

If we have one portlet, and we use this tld into the jsp:
<liferay-portlet:renderURL plid="13605" portletName="mynews_WAR_myresourcesportlet" var="prueba"></liferay-portlet:renderURL> and this portlet creates a link to other portlet, in this case, mynews_WAR_myresourcesportlet located in the page with plid 13605. This link is a render link.

The next sample shows how to create an actionURL:
<liferay-portlet:actionURL name="newMyNew" plid="13605" portletName="mynews_WAR_myresourcesportlet" var="prueba2"></liferay-portlet:actionURL>

We can also pass parameters:
<liferay-portlet:renderURL plid="13605" portletName="mynews_WAR_myresourcesportlet" var="prueba">

  <liferay-portlet:param name="resourcePrimKey" value="123456" />
</liferay-portlet:renderURL>

If the plid is not used, the portal assumes that the portlets are located into the same page.

5 comments:

  1. You deal quite well with portlets. I see that's how it should have been done. I get the pass parameters command bit mixed up sometimes.

    ReplyDelete
  2. Nice!! Strangely, I found the same article here also
    http://www.zylk.net/web/guest/web-2-0/blog/-/blogs/how-to-link-portlets-located-on-different-pages-in-liferay-portal

    ReplyDelete
  3. Excellent Stuffs. Thank you Sir !

    ReplyDelete
  4. It works like a charms! Thanks!!

    ReplyDelete