Multiple render method in Liferay MVC Portlet

Multiple render in portlet is used to show different views. This is required when different actions requires different results to show.
Many times we need different views to display the output after various action performed. In liferay MVC view.jsp is use to render portlet output.

Let us see by example. Suppose, our portlet shows the list of students in tabular format. It shows Student Name, Age and Standard. Name is a clickable and on clicking it, it will show full details about the students (like his/her address, parents name, contact no etc).

In this case we need to put multiple render logic (one is to show student list and second is to display student details) in one jsp (view.jsp) with if-else condition.

This will not only mass up view.jsp  but creates complexity. If we display multiple render logic in separate jsp, it’s easy to maintain.

In this article we will see step by step, how to achieve multiple render (jsp) in Liferay MVC portlet.


Refer my previous blog on How to create custom Liferay Portlet and create liferay MVC portlet. Give project name as multiple-render and eclipse will append -portlet at the end so that final project name will become multiple-render-portlet.

Create portlet class call called  MultipleRenderPortlet under package com.opensource.techblog.portlet. Also update portlet class entry in portlet.xml file. After this the project structure will look like below screenshot.
Multiple render method in Liferay MVC Portlet - project-structure
You can observe that by default view.jps has been created at root level under /docroot folder.

I would recommend looking at the index page ‘A Complete Liferay Guide‘ to browse all topics about Liferay.


Add following code to portlet class

package com.opensource.techblog.portlet;


import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;
import javax.portlet.ProcessAction;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;

public class MultipleRenderPortlet extends MVCPortlet{

 public void render(RenderRequest request, RenderResponse response)
   throws PortletException, IOException {
  String renderPageName = ParamUtil.get(request, "renderPage", "studentList-jsp");
  String renderPagePath = getInitParameter(renderPageName);
  include(renderPagePath, request, response);
  super.render(request, response);
 public void showStudenDetailPage(ActionRequest actionRequest, ActionResponse actionResponse)throws IOException, PortletException, PortalException, SystemException{
  String renderPageName = ParamUtil.get(actionRequest, "pageName", "studentList-jsp");
  actionResponse.setRenderParameter("renderPage", renderPageName);

More explanation in the Final Flow section of this blog.

STEP-3: Add two JSPs- Multiple render

Add two JSP called studentDetail.jsp and studentList.jsp at root level (under docroot folder). After doing this, the project structure will look like below screenshot.

Multiple render method in Liferay MVC Portlet - adding-two-new-jsp

In this scenario, First, studentList.jsp will be displayed. Clicking on the link in this JSP, studentDetail.jsp should display. To explain, how to have multiple render (jsp) in Liferay MVC, I have put pseudo code.

In studentList.jsp, we will create one link which will simply show the output of studentDetail.jsp.

Let me explain, what is the approach to display multiple render(jsp) in Liferay MVC portlet. Following image shows this approach.

Multiple render method in Liferay MVC Portlet - Approach-of-multiple-render


  • We will have view.jps, which we will keep it blank. View.jsp is the default jsp which will show final output.
  • First, we have to render studentList.jsp. So in render method of Liferay MVC portlet class, we will include it.
  • in studentList.jsp file, we will create link, which simply point to studentDetail.jsp.
  • We will point to respective jsp by its path defined in portlet.xml file

Next, add code to studentList.jsp so that it will look like the below snippet
<%@ taglib uri="" prefix="portlet" %>

<portlet:defineObjects />

<portlet:actionURL name="showStudenDetailPage" var="studentDetailUrl">
 <portlet:param name="pageName" value="studentDetail-jsp"></portlet:param>

This is student list JSP.

<a href="${studentDetailUrl}">Go To Student Detail JSP</a>
  • We have created an action URL and passing one parameter called pageName, which we will access in the action method in the portlet class.

 STEP-4: ADD Path of studentDetail.jsp and studentList.jsp in portlet.xml file

Next, we will define the path of this jsp as initial parameters of the portlet in portlet.xml file, so that it will look like the below snippet
<?xml version="1.0"?>

  <display-name>Multiple Render</display-name>
   <title>Multiple Render</title>
   <short-title>Multiple Render</short-title>
   <keywords>Multiple Render</keywords>
  • You can observe that we have added two init-param and defined the respective JSP path.
  • These init-params we can access in portlet class to get the jsp path.

Final Flow

  • When we place the portlet on the page, its render method (defined in portlet class in STEP-2 ) will be called.
  • In this(render) method, we are getting request parameters by calling the get method of Liferay util class ParamUtil.
  • get method of ParamUtil will take 3 parameters. First is the PortletRequest from where we will get the parameter, second is the parameter name(renderPage) and third is the default value in case if the parameter will not found in the request.
  • The first time we will not get renderPage parameter. So it will return studentList-jsp.
  • Then we are calling getInitParameter method and passing the value of renderPage parameter. So first time it will search for init parameter studentList-jsp.
  • We have defined an init parameter called studentList-jsp and its value is path of studentList.jsp in portlet.xml file. So first time, it will give path of studentList.jsp
  • The next is, calling method include a method and passing the path of studentList.jsp,request and response objects.
  • include method simply include the output of studentList.jsp file into view.jsp file.
  • Since we kept view.jsp as blank, we will get the final output as studentList.jsp file.
  • In studentList.jsp , we created one link and passing action url with one parameter called pageName. Value of this parameter is studentDetail-jsp(which is nothing but the init parameter name which we have defined in portlet.xml file.
  • When we click the link, the process action method will be called. We have defined the name attribute in action url with matching name value of @processAction  annotation in portlet, so it will call process action method called showStudenDetailPage .
  • In this action method, we are getting the request parameter pageName, which we have passed in action url in studentList.jsp file.
  • soon after we are calling actionResponse.setRenderParameter and passing the value of pageName in it.
  • In Portlet, soon after the action method call, portlet container will call render method.That is the reason, we make void return type of process action method.
  • actionResponse.setRenderParameter method will set the parameter in request object, so that it will be available in render method. Note that this is not equivalent of request.setAttribute. In render method we can access this request parameter.
  • When control goes to render method, we will get this render parameter (pageName which is nothing but the init parameter of studentDetail.jsp file), and passing it to getInitParameter method will give the path of studentDetail.jsp file.
  • On clicking include method, the output of studentDetail.jsp will be included in view.jsp file.
  • Since view.jsp is blank, the output will be of studentDetail.jsp file.
So finally it will look like the below screenshot.
As soon as we place the portlet on page, output of studetnList.jsp as below screenshot
Multiple render method in Liferay MVC Portlet - studentList.jsp
When we click on the link Go To Student Detail JSP, it will show output of studentDetail.jsp. Since we kept only one line in studentDetail.jsp file, it will show the final output as below
Multiple render method in Liferay MVC Portlet - studentDetail.jsp
In short, it’s only one render method but it will serve multiple JSP files.

Summing Up

  • Out of the box, Liferay MVC portlet has only one JSP (view.jsp)
  • It’s easy to maintain multiple render logic if it’s placed in different views.
  • We can point which view we want to render in portlet class.
I would recommend looking at the index page ‘A Complete Liferay Guide‘ to browse all topics about Liferay.

Download Source code 
Download Source

Recommended For You

About the Author: Nilang

Nilang Patel is a technology evangelist who loves to spread knowledge and helping people in all possible ways. He is an author of two technical books - Java 9 Dependency and Spring 5.0 Projects.

7 Comments to “Multiple render method in Liferay MVC Portlet”

  1. Thanks for the post.
    you have not mentioned the way how can we transfer the id that actually the JSP which student detail to display.

    the bottom line please tell us how can the studentDetail.jsp receive an id from studentList.jsp if the list has multiple dynamic data records

    1. Hi Hatem,

      Welcome to Tech blog and thanks for appreciation. Answer to your question:-

      From any JSP, when page get submitted, it will reach to ‘render’ method or portlet and from there you can redirect to multiple JSPs. So you can pass id from studentList.jsp as a parameter, once receive in ‘render’ method of portlet, set it to request attribute and then it will be available studentDetail.jsp

      Let me know if this clarify your question. Feel free to ask questions / give suggestions.


  2. Hello,
    I have a portlet that displays search results in a table (a list of projects). Then when the user clicks on a specific project, I need the project detail information to open up in a separate tab. I have a project search jsp and a detail jsp page that loads (via jquery load) in a separate tab. But how do I pass an attribute to the detail jsp page (like the project id or the whole project model)? Please let me know if there’s a better way to accomplish this behaviour.

    1. Hi Ruchi,
      First of welcome to Techblog. In this case when you click on perticular link (to open detail jsp) you can store the PK of each record and pass it while triggering the click on that link to open detail.jsp. Let me know if you need any other help.


    1. Hi Mahesh,

      Thanks for writing and welcome to tech blog. Yes you can have doView() and render() in same portlet. But in real scenario, render() is enough, you no need to have two methods. For sequence, I guess doView() will be called first. However you can put some logger and see which one is called first.


Leave a Reply

Your email address will not be published. Required fields are marked *

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