
We can develop hook to ย implement our own Custom Action. So what does it mean by Custom Action? Just open portal.properties in your liferay source code. You will see many entries which contains events. For exampleย login.events.pre,ย login.events.post and many more. These are simply called actions and every action has its specific task. Theย login.events.preย events (or action) does something ย before user log in and similarlyย login.events.post does some specific task after login. If you look into portal.properties you will see many other events or actions. So if we want our own action (or event) then how are we going to implement it. ย By Hook we can implement our Custom Action. This article explains the details about it.

ย
1. Create Liferay Plugin project of type Hook
The first step is you have to create Liferay Plugin Project of type hook. Follow the postย
https://proliferay.com/basics-liferay-hook-development/
2.ย Create newย classย CustomPreLoginAction
This is the class we will call as Custom Action. The content of the class should be like thisย
package com.proliferay.demo;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.liferay.portal.kernel.events.Action;
import com.liferay.portal.kernel.events.ActionException;
/**
*
* @author Hamidul Islam
*
*/
public class CustomPreLoginAction extends Action{
@Override
public void run(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
throws ActionException {
/**
* Write your custom code here
*/
System.out.println("Invoking this line before Login");
}
}
Note 1: If your Custom Action needs http servlet request and response extends the class com.liferay.portal.kernel.events.Action
Note 2: If your Custom Action does not require any request response object then extends the classย com.liferay.portal.struts.SimpleAction
Note 3: Bothย com.liferay.portal.kernel.events.Action andย com.liferay.portal.struts.SimpleAction are abstract class. Weย must add unimplemented method in our Custom Action.
Note 4:ย In run method write your custom code.ย
3.ย Tell Liferay thatย CustomPreLoginAction is the pre login action
This is simply done by adding below in ourย portal.properties
#Tue Dec 09 12:39:53 IST 2014 login.events.pre=com.proliferay.demo.CustomPreLoginAction
4.ย Yo have to tell Liferay where the portal.properties exist
This is done by
<?xml version="1.0"?> <!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.2.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_2_0.dtd"> <hook> <portal-properties>portal.properties</portal-properties> </hook>
“Look the source code for details.
This is all about creating Custom Action by Hook. Deploy the hook. Before log in you will see the message
//ย System.out.println(“Invoking this line before Login“);
As mentioned in our custom action.ย
ย


Hi!!!!, thanks for your tutorial, I like your blog.
How to import the zip file into eclise?
That zip file is created by you? or liferay’s sign-in portlet?
so many doubts are there.. Please explain me
Regards,
Rithika
This is a nice tutorial and it helped me a lot