; last updated - 2 minutes read

Liferay has a nice feature to influence the behavior of the portal by deployable items. Among other things, you can use these "hooks" to call a java method if the user logs in or logs off again. My particular use case was to show different pages to different user groups.

Hooks are described nicely at their wiki. Unfortunately, this description is a little outdated. For the sake of convenience, I jot down the basic steps to write a hook.

Creating a hook is easy if you use Liferay's SDK. Create an ext hook. The project created by the Liferay SDK should look like this:

The most important file is the file liferay-hooks.xml. This file is described in the Liferay wiki, showing us that the <event>-tag is what we are looking for.

Unfortunately, the <event>-tag isn't allowed since Liferay 5.2. You can substitute it by putting a portal.properties file into the hook. This file is the same as the portal-ext.properties you can put into the root-context of Liferay, apart from being part of the deployable (and undeployable) hook. Put the properties file into the folder WEB-INF/src and leave a reference to this file in the liferay-hooks.xml like so:

my-portal-ext.properties

Now have a look at the original portal.properties you find in the portal-impl.jar. It contains the complete list of possible hooks you can use. To define the landing page, find the login hook:

login.events.post=com.liferay.portal.events.LoginPostAction

Copy this line into your my-portal-ext.properties, replacing the class name by another class name. A good starting point to implement your own login post action is the original class. Copy this from Liferay's source code and adapt it to your own needs.


Comments