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.
“In this article we will demonstrate how to create our own Pre Login Action by Hook
Â
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