Liferay Render URLs Example

This article explains what are the Liferay render URLs and an example implementation of render URLs on a Liferay application.

To invoke the render phase of the portlet, we can use the Liferay render URLs. The render phase always executes after the execution of the action phase. Render requests execution can be either sequential or parallel.

In Liferay, we can set the order of render request execution by setting the render-weight parameter inside the liferay-portlet.xml file.

In this example, we will see how to create a render URL using the tg library and Java code.

Versions used: Liferay 6.2 + Apache Tomcat 7.

Creating Liferay render URLs

The first step is to import the portlet tag library to the view.jsp file.

<%@ taglib uri="" prefix="portlet" %>

Add the following code on the view.jsp file.

We are adding a render parameter named “renderParam” for render URL, and we are rendering jsp page page2.jsp on clicking the anchor tag.

The var attribute is the reference of the render URL that we can use inside the scope of this URL.

<portlet:renderURL var="renderPortletURL" >
 <portlet:param name="jspPage" value="/html/liferayrenderurl/page2.jsp"/>
 <portlet:param name="renderParam" value="myRenderVal"/>

<a href="<%=renderPortletURL %>" >Render URL</a>

Create a new jsp page called page2.jsp that gets rendered by clicking the tag on the view.jsp page. Add the following code.

We are retrieving the render URL parameter(“renderParam”) and displaying it on UI.

<%@page import="com.liferay.portal.kernel.util.ParamUtil"%>
<%@ taglib uri="" prefix="portlet" %>

<% String renderParam = ParamUtil.getString(request, "renderParam"); %>

Render Parameter is: <%=renderParam %>

Below is the code snippet of the creation of render URL using Java code.

<%@page import="javax.portlet.PortletRequest"%>
<%@page import="com.liferay.portal.kernel.util.WebKeys"%>
<%@page import="com.liferay.portal.kernel.util.ParamUtil"%>
<%@page import="com.liferay.portal.theme.ThemeDisplay"%>
<%@page import="com.liferay.portlet.PortletURLFactoryUtil"%>
<%@page import="javax.portlet.PortletURL"%>
<%@ taglib uri="" prefix="portlet" %>

<% ThemeDisplay td = (ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
PortletURL renderPortletURL = PortletURLFactoryUtil.create(request, td.getPortletDisplay().getId(), td.getPlid(), PortletRequest.RENDER_PHASE);
renderPortletURL.setParameter("jspPage", "/html/liferayrenderurl/page2.jsp");
renderPortletURL.setParameter("renderParam", "myRenderVal");

<a href="<%=renderPortletURL %>" >Render URL</a>

Testing the output

The below images shows the created render URL.


On clicking the URL, UI displays the render parameter without refreshing the web page.


Also, check how to use Liferay Action URL and Liferay Resource URL.


In this article, we learned how to implement Liferay render URLs.