
Without action URL we can’t imagine portlet development. In this article we will discuss about action URL in Liferay. In simpleย by action URL we invoke process action of portlet’s life cycle. By the end of this article we will know the various way ย to create action URL in Liferay. This article is very basic which will be helpful for the beginners.ย
1. What’s Action URL
To be simple its just a URL in UI. But the main aim of the action URL is to invoke process action like
@ProcessAction(name = "addBook")
public void addBook(ActionRequest actionRequest,ActionResponse actionResponse){
//Some logic here
}
So in UI we create Action URL and once Action URL is invoked it executes some java code (which is called nothing but process action) in the server side.
2. Create Action URL by RenderResponse object
So how to get renderResponse object in our JSP? Its quite simple. By adding below code in our JSP renderResponse object will be ready to use
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> <portlet:defineObjects />
Lets see how to create actionURL from renderResponse object
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@page import="javax.portlet.PortletURL"%>
<portlet:defineObjects />
<%
PortletURL actionURL = renderResponse.createActionURL();
actionURL.setParameter("javax.portlet.action", "someProcessAction");
%>
<a href="<%=actionURL%>">Call Process Action</a>
And corresponding process action
@ProcessAction(name="someProcessAction")
public void someProcessAction(ActionRequest actionRequest, ActionResponse actionResponse){
System.out.println("#######Calling some process action##############");
}
3.ย Send some parameter while invoking actionURL
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@page import="javax.portlet.PortletURL"%>
<portlet:defineObjects />
<%
PortletURL actionURL = renderResponse.createActionURL();
actionURL.setParameter("javax.portlet.action", "someProcessAction");
actionURL.setParameter("some-parameter", "some-value");
%>
<a href="<%=actionURL%>">Call Process Action</a>
Retrieve Value in process action
@ProcessAction(name="someProcessAction")
public void someProcessAction(ActionRequest actionRequest, ActionResponse actionResponse){
String value = ParamUtil.getString(actionRequest, "some-parameter");
System.out.println("#######Value##############"+value);
System.out.println("#######Calling some process action##############");
}
4.ย Set window state in action URL
<%@page import="com.liferay.portal.kernel.portlet.LiferayWindowState"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@page import="javax.portlet.PortletURL"%>
<portlet:defineObjects />
<%
PortletURL actionURL = renderResponse.createActionURL();
actionURL.setParameter("javax.portlet.action", "someProcessAction");
actionURL.setWindowState(LiferayWindowState.MAXIMIZED);
%>
<a href="<%=actionURL%>">Call Process Action</a>
We have set window state to MAXIMIZED. That means when we invoke the action URL the size of the portlet will be maximized.
Note:
i) When ย window state is MAXIMIZED the portlet occupy the whole page of the portal page.
ii) Only one portlet can be in MAXIMIZED stateย for a givenย page. For example if there are 5 portlets in a page andย if any portlet goes to MAXIMIZED state then other portlets will be hidden
iii)ย We can use different window states by using the classย com.liferay.portal.kernel.portlet.LiferayWindowState.
5. Create action URL by tagย portlet:actionURL
This is theย easiest way to create action URL. For example
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> <portlet:defineObjects /> <portlet:actionURL var="actionURL" name="someProcessAction"/> <a href="<%=actionURL%>">Call Process Action</a>
Variousย attributes ofย portlet:actionURL Tag
windowState (Type: String,non-required) –ย indicates the window state that theย portlet should have when theย link is executed. These are theย window states areย predefined: minimized, normal, and maximized. If the specified window state isย illegal for the current request, a JspException isย thrown. Reasons for a ย window state being illegal may include that the portal does not support this state,ย the portlet has not declared in its deployment descriptor that it supports this state,ย or the current user is not allowed to switch to ย this state. If a window state is notย set for a URL, it should stay the same as the window state of the currentย request.The window state attribute is not case sensitive.
portletMode (Type: String, non-required) โย indicates the portlet mode that theย portlet must have when this link is executed, if no error condition ocurred.ย Theseย are theย portlet modes are predefined: edit, help, and view. If theย specified portlet mode is illegal for the current request, a JspExceptionย is thrown.ย Reasons for a portlet mode being illegal may include that the portalย does not support this mode, the portlet has not declared in its deploymentย descriptor that it supports this mode for the current markup, or the current user isย not allowed to switch to this mode. If a portlet mode is not set for a URL, it mustย stay the same as the mode of the current request. The portlet mode attribute isย not case sensitive.
var (Type: String, non-required) โย name of the exported scoped variable for theย action URL. The exported scoped variable must be a String. By default, theย result of the URL processing is written to the current JspWriter. If the result isย exported as a JSP scoped variable, defined via the var attributes, nothing isย written to the current JspWriter.
After the URL is created it is not possible to extend the URL or add anyย further parameter using the variable and String concatenation. If the given
variable name already exists in the scope of the page or it is used within anย iteration loop, the new value overwrites the old one.
secure (Type: String, non-required) โย indicates if the resulting URL should be aย secure connection (secure=”true”) or an insecure one (secure=”false”). If theย specified security setting is not supported by the run-time environment, aย JspException isย thrown.If the security is not set for a URL, it mustย stay the same as the security setting of the current request.
copyCurrentRenderParameters (Type: boolean, non-required) โย if set to trueย requests that the private render parameters of the portlet of the current requestย isย attached to this URL. It is equivalent to setting each of the currentย private render parameters via the <portlet:param> tag. If additionalย <portlet:param> tags are specified parameters with the same name as anย existing render parameter will get merged and the value defined in additionalย <portlet:param> tags must be pre-pended.ย The default for this attribute is false.
escapeXml (Type: boolean, non-required) โย determines whether charactersย ย <,>,&,’,” in the resulting output should be converted to their correspondingย character entity codes. For example
< gets converted to <
ย > gets converted to >
ย & gets converted to &
‘ gets converted to '
“ย gets convertedย to "
Default value is true.
name (Type: String, non-required) โ specifies the name of the action that can be used by GenericPortlet to dispatch to methods annotated with ProcessAction. Setting this name will result in adding a parameter to this action URL with the name javax.portlet.action.


Nice explanation. Could you please give sample example of portlet which consists of four button new, edit, delete, select action on one form.
Many thanks !!
this is required without javascript.