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:
- Create Liferay Plugin Project of type Hook.
- Create a new class CustomLoginAction.
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..............");
}
}
- 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
- 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>
- 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)