Blogs
Liferay provides us facility to execute some code before and after of some specific events, namely Login, Logout and Service. Login and Logout are self-explanatory, Service is the event that takes place before or after every Action. For instance, If we have CustomServicePreAction and CustomLoginPreAction, in that case CustomServicePreAction will be called first then CustomLoginPreAction and then the LoginAction class will be invoked.
To achieve this, we need to make some entry in the portal-ext.properties, however some values are already present in portal.properties file, we have to update those properties, as following:
servlet.service.events.pre=com.liferay.portal.events.ServicePreAction, com.liferay.portal.events.CustomServicePreAction servlet.service.events.post=com.liferay.portal.events.ServicePostAction, com.liferay.portal.events.CustomServicePostAction
login.events.pre=com.liferay.portal.events.LoginPreAction, com.liferay.portal.events.CustomLoginPreAction login.events.post=com.liferay.portal.events.LoginPostAction, com.liferay.portal.events.DefaultLandingPageAction, com.liferay.portal.events.CustomLoginPostAction logout.events.pre=com.liferay.portal.events.LogoutPreAction, com.liferay.portal.events.CustomLogoutPreAction logout.events.post=com.liferay.portal.events.LogoutPostAction, com.liferay.portal.events.DefaultLogoutPageAction, com.liferay.portal.events.SiteMinderLogoutAction, com.liferay.portal.events.CustomLogoutPostAction
- com.liferay.portal.events.CustomServicePreAction,
- com.liferay.portal.events.CustomServicePostAction,
- com.liferay.portal.events.CustomLoginPreAction,
- com.liferay.portal.events.CustomLoginPostAction,
- com.liferay.portal.events.CustomLogoutPreAction, and
- com.liferay.portal.events.CustomLogoutPostAction.
Now we have to add the following classes in Ext:
1. CustomServicePreAction
package com.liferay.portal.events;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.liferay.portal.kernel.events.Action;
/**
* @author apoorva.prakash
**/
public class CustomServicePreAction extends Action {
public void run(HttpServletRequest request, HttpServletResponse response)
throws ActionException {
System.out.println("this is custom service preaction");
}
}
package com.liferay.portal.events;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.liferay.portal.kernel.events.Action;
/**
* @author apoorva.prakash
**/
public class CustomServicePostAction extends Action {
public void run(HttpServletRequest request, HttpServletResponse response)
throws ActionException {
System.out.println("this is custom service post action");
}
}
package com.liferay.portal.events;
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 apoorva.prakash
**/
public class CustomLoginPreAction extends Action {
public void run(HttpServletRequest request, HttpServletResponse response)
throws ActionException {
System.out.println("this is CustomLoginPreAction...");
}
}
package com.liferay.portal.events;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.liferay.portal.kernel.events.Action;
import com.liferay.portal.kernel.events.ActionException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
/**
* @author apoorva.prakash
**/
public class CustomLoginPostAction extends Action {
public void run(HttpServletRequest request, HttpServletResponse response)
throws ActionException {
System.out.println("this is CustomLoginPostAction...");
}
}
package com.liferay.portal.events;
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 apoorva.prakash
* */
public class CustomLogoutPreAction extends Action {
public void run(HttpServletRequest request, HttpServletResponse response)
throws ActionException {
System.out.println("this is CustomLogoutPreAction");
}
}
package com.liferay.portal.events;
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 apoorva.prakash
**/
public class CustomLogoutPostAction extends Action {
public void run(HttpServletRequest request, HttpServletResponse response)
throws ActionException {
System.out.println("this is CustomLogoutPostAction");
}
}
And now, run your code. It will work. :)
This article focuses implementation of events customization purely with EXT-plugins, however the same can be achieved with the help of hooks also.

