Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Liferay: How to create Custom Action By Hook?

    • 0
    • 2
    • 1
    • 2
    • 0
    • 0
    • 0
    • 0
    • 348
    Comment on it

    We can modify Liferay JSP, services, properties by using Hooks. One of the main use of Hook is we can implement our Custom Action.


    So what is Custom Action?

    When you see portal.properties in your liferay source code. You will see there multiple entries which contain events. For example login.events.pre, login.events.post etc. These events are called actions and every action has its own specific task. The login.events.pre events (or action) defines the task before user log in and login.events.post defines task after user login.


    I'm taking here example of creating Custom Action for "login.events.post" event.

    Follow the below steps to create Custom Action:

    1. Create Liferay Plugin Project of type Hook.

    2. Create a new class CustomLoginAction.
    3. This class is the Custom Action.
    package com.evon.action;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import com.liferay.portal.kernel.events.Action;
    import com.liferay.portal.kernel.events.ActionException;
    
    public class CustomLoginAction extends Action{
    
       @Override
        public void run(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
                throws ActionException {
            /**
             * Write your custom code here, this code will run after user logged in
             */
            System.out.println("In Action after login..............");
    
        }
    }
    
    1. Now tell Liferay that CustomLoginAction is the post login action by adding below line in your portal.properties
    #Tue June 16 17:04:57 IST 2015
    login.events.post=com.evon.action.CustomLanding
    1. Now define the below line in "liferay-hook.xml" to tell Liferay where the portal.properties exist.
    <?xml version="1.0" encoding="UTF-8"?>
    <!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>
    
    1. Deploy the Hook and try to login. After logged in you will see the message that you mentioned in our custom action.
    // System.out.println("In Action after login..............");
    

    Hope this will help you :)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: