To invoke render phase of portlet, we can use render URL. Render phase is always executed after the execution of action phase. Render requests may be executed sequentially or in parallel. In liferay, we can set the order of render request execution by setting render-weight parameter inside liferay-portlet.xml file.

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

  • Import portlet tag library to the view.jsp file:
<%@ taglib uri="" prefix="portlet" %>
  • Add the following code on view.jsp file. Here, we are setting a parameter for render URL named as “renderParam” and also we are rendering jsp page page2.jsp on clicking the anchor tag. the var attribute is the reference of the render URL, which can be used 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, which will be rendered on clicking the tag on view.jsp page. Add the following code. Here, we are retrieving the render URL parameter named “renderParam”,  which was set on view.jsp page and displaying on UI.
<%@page import="com.liferay.portal.kernel.util.ParamUtil"%>
<%@ taglib uri="" prefix="portlet" %>

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

Render Parameter is: <%=renderParam %>
  • Following is the code snippet of 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>
  • Following are the outputs:



Check how to use Liferay Action URL and Liferay Resource URL.

Note: Versions used: Liferay 6.2 + Apache Tomcat 7.