create action URL By Liferay tag (liferay-portlet:actionURL) in JSP

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

liferay-portlet:actionURL is one of the very useful tag provided by Liferay. In this article, I will be showing how this tag is used to create actionURL in JSP. Action URL created by this tag works similarly as action URL created by PortletURLFactoryUtil class Let’s see this.

actionURL by liferay-portlet:actionURL Tag

First you need to create Liferay MVC Portlet. Give plugin project name as actionURL-by-LiferayTag and “-portlet” will be appended by Liferay IDE during project creation. Give portlet class as com.opensource.techblog.portlet.ActionURLByLiferayTagPortlet. The project structure should look like below screenshot.liferay-portlet:actionURL - Project-structure

Now, add the following code in

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.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;

public class ActionURLByLiferayTagPortlet extends MVCPortlet {

	//define log for this class
	private static final Log _log = LogFactoryUtil.getLog(ActionURLByLiferayTagPortlet.class.getName());

	public void render(RenderRequest request, RenderResponse response)
			throws PortletException, IOException {" This is render method of RenderURLByLiferayTagPortlet");
		super.render(request, response);
	public void actionMethodFromLiferayTag(ActionRequest request, ActionResponse response)
			throws IOException, PortletException, PortalException, SystemException{
		String param=ParamUtil.get(request, "sampleParam", "");"parameter is ==>"+param);


  • First I have created log variable – _log. In liferay LogFactoryUtil class is used to get log for current class. This variable will be used to display logs in server console.
  • I have overridden the render() method. This method simply showing sample logs.
  • Next, I have defined action method actionMethodFromLiferayTag. In this action method, I am reading request parameter (ParamUtil is used to read request parameter) and displaying it in log. This action method will be called when user clicks on action URL (generated by liferay-portlet:actionURL tag in JSP)

Next, add the following code to view.jsp

<%@page import="com.liferay.portal.theme.ThemeDisplay"%>
<%@page import="com.liferay.portal.kernel.portlet.LiferayPortletMode"%>
<%@page import="com.liferay.portal.kernel.portlet.LiferayWindowState"%>
<%@ taglib uri="" prefix="portlet" %>
<%@ taglib uri="" prefix="liferay-portlet" %>
<%@ taglib uri="" prefix="liferay-theme" %>

<portlet:defineObjects />

<liferay-portlet:actionURL var="actionURLByLiferayTag" name="actionMethodFromLiferayTag" 
  windowState="<%=LiferayWindowState.NORMAL.toString()%>" portletMode="<%=LiferayPortletMode.VIEW.toString() %>"
  plid="<%=themeDisplay.getPlid() %>" portletName="<%=themeDisplay.getPortletDisplay().getId() %>" >
  <liferay-portlet:param name="sampleParam" value="This is sample param value"/>

<a href="${actionURLByLiferayTag}">Action Url created by Liferay TAG in JSP</a>


  • I have added Liferay-portlet:actionURL tag in JSP. This tag is used to create action URL.
  • To avail this tag, you need to add following taglib definition
    • <%@ taglib uri=”” prefix=”liferay-portlet” %>
  • Attributes of liferay-portlet:actionURL tag is similar as portlet:actionURL tag. The difference between these two tags (liferay-portlet:actionURL and portlet:actionURL ) are as below
    • Action URL created with <portlet:actionURL> can point to current portlet only.
    • Action  URL created with <(liferay-portlet:actionURL> can point to other portlet too. For this you need to give value of plid and portletName attribute for target portlet. 
    • While using <liferay-portlet:actionURL> tag,if you do not provide plid and portletName then (by default) it will take current portlet’s plid and portletName. Means such action URL (if plid and portletName are not provided then) points to current portlet only.
  • You can set window state and portlet mode similarly <portlet:actionURL>
  • We can also pass additional parameter with <liferay-portlet:param> tag similarly <portlet:param> tag.
  • var attribute is used to hold this action URL so that we can refer it anywhere in JSP.
  • In the end, we created a new link and set its href with this variable (var attribute defined in <liferay-portlet:param> tag) which holds action URL.

Save the view.jsp and deploy the portlet. Refresh the page and you will see this link. When you click this link, our action method will be called and you will see the parameter’s (sampleParam) value (“This is sample param value”) is printed in server console.

Summing Up

  • <liferay-portlet:actionURL> liferay tag used to create action URL
  • We can set portlet mode and window state while creating actionURL
  • We can pass additional parameter by <liferay-portlet:param> child tag (just like <portlet:param> in <portlet:actionURL>)
  • actionURL created by <liferay-portlet:actionURL> tag can points to same as well as other portlets.
  • If you wish to point other portlet’s action method then you need to pass that portlet’s plid and portletName.
  • You may visit this link to understand render and action phase of portlet.

Following are other possible ways to create action URL in Liferay

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.

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.