• Custom Action by Liferay Hook

    Posted on December 9, 2014 by Hamidul Islam in Liferay.

    Custom Action By Hook

    aimWe 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.prelogin.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.

    Create Custom Action By Hook

    "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 


    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{
    	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

    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">

    "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. 


    Download Source Code


    Post Tagged with , ,

3 Responses so far.

  1. Andry says:

    Hi!!!!, thanks for your tutorial, I like your blog.

  2. Rithika Sri says:

    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



  3. Muzammil says:

    This is a nice tutorial and it helped me a lot

%d bloggers like this:

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.