Performing a Custom Action

Hooks are useful for triggering custom actions on common portal events, like user log in or system start up. The actions for each of these events are defined in, so we’ll need to extend this file to create a custom action. Hooks make this a simple task.

  1. Create the directory example-hook/docroot/WEB-INF/src/com/liferay/sample/hook, and create the file inside it with this content:

    package com.liferay.sample.hook;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class LoginAction extends Action {
        public void run(HttpServletRequest req, HttpServletResponse res) {
            System.out.println("## My custom login action");
  2. Create a file inside example-hook/docroot/WEB-INF/src with this content:
  3. Edit liferay-hook.xml inside example-hook/docroot/WEB-INF, adding the following line above <custom-jsp-dir>:

  4. Redeploy your hook. Once deployment is complete, log out and back in, and you should see your custom message, ## My custom login action, displayed in the terminal window running Liferay.

Custom action hook plugins aren’t limited to the log in event. You can define custom actions for other events, too. For actions that require access to the HttpServletRequest, extend; for others, extend com.liferay.portal.struts.SimpleAction.

Extending and overriding portal properties is just as easy, so let’s do that next.

« Customizing Sites and Site Templates with Application AdaptersExtending and Overriding »
Was this article helpful?
0 out of 0 found this helpful