create render URL By Liferay tag (liferay-portlet:renderURL) in JSP

liferay-portlet:renderURL is a custom tag provided by Liferay. This tag is used to create render URL.

In this article, I will be showing how to create render URL by liferay tag (liferay-portlet:renderURL)This tag works similarly as render URL by PortletURLFactoryUtil class. 

First of all, you need to create LiferayMVC portlet. You can refer separate blog on Creating MVC Portlet in Liferay to create project structure as per below screenshot.

render URL By Liferay tag (liferay-portlet:renderURL) in JSP - project stucture

I gave plugin project name as renderURL-by-LiferayTag and -portlet will be appended during project creation by Liferay IDE. I gave portlet class as com.opensource.techblog.portlet.RenderURLByLiferayTagPortlet.

Add following code in RenderURLByLiferayTagPortlet class.

Explanation:-

  • We are simply reading request parameter and displaying it in logger. 

Add Liferay Tag (liferay-portlet:renderURL)

We will pass this parameter while creating render URL with Liferay Tag. We will add liferay tag in view.jsp. Next step is to add following code in view.jsp

 Explanation:-
  • <liferay-portlet:renderURL> tag is used to create render URL. 
  • To avail this tag, we have added <%@ taglib uri=”http://liferay.com/tld/portlet” prefix=”liferay-portlet” %> taglib definition in this jsp.
  • attribute of this tag is similar with <portlet:renderURL>. You can refer my blog on creating render URL with Portlet tag (<portlet:renderURL>).The only difference between these two tags are
    • Render URL created with <portlet:renderURL> can point to current portlet only.
    • Render URL created with <liferay-portlet:renderURL> can point to other portlet too. For this we need to give plid and portletName attribute for target portlet. 
    • If we are not providing these attribute to <liferay-portlet:renderURL> tag then it will create render URL which points to current portlet only.
  • You can set window state and portlet mode similarly that we set for <portlet:renderURL>
  • You can also pass additional parameter with <liferay-portlet:param> tag similarly <portlet:param> tag.
  • var attribute is used to hold this render URL so that we can refer it anywhere in JSP.
  • At the end we created new link and set its href with variable (var attribute defined in <liferay-portlet:param> tag) which holds render URL.

Save view.jsp and deploy the portlet. Refresh the page and you will see this link. Click on this link and you will see the paramter’s (param) value (“This is from Liferay TAG”) is printed in server console.


Summing Up

  • <liferay-portlet:renderURL> liferay tag used to create render URL
  • We can set portlet mode and window state while creating renderURL
  • We can pass additional parameter by <liferay-portlet:param> child tag just like <portlet:param> under <portlet:renderURL>.
  • renderURL created by <liferay-portlet:renderURL> tag can points to same as well as other portlets.
  • You may visit this link to understand render and action phase of portlet.

Following are other possible ways to create render URL in Liferay

Download Source

Download Source

Share This Post

Post Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.