Learn Liferay7/DXP Filter Hook in 10 Minutes


May 3, 2022

In my last post, I discussed about action hook. In this post, you will learn about filter hook in Liferay7/DXP.

Just a quick recap in case you have not read my previous post. Liferay provides mechanism to override behaviour for out-of-the-box features is called hook. Liferay supports following types of hook,

  • Struts Action Hook
  • Filter Hook
  • Jsp Hook
  • Language properties Hook
  • Model Listener hook
  • Service Wrapper Hook

After looking at above list of filters, you may have question that where filter hook is applicable in development?

Filter hook are used for intercepting HTTP request to execute piece of code before it reaches to execution logic. This is like HTTP Filter.

Following are the prerequisite to start with hook development in Liferay 7/DXP.


There is a difference in way to implement hook in Liferay 7/DXP compare to prior versions as DXP does not provides option for XML configurations. Now Let’s create Filter hook in liferay7/DXP using following steps,

  1. Create Liferay Workspace Project:

    To create a Liferay Workspace in IDE follow the following steps:

Select File menu → click New → select Liferay Workspace Project. Upon creation of the workspace, the structure should look like below:

Create Liferay Workspace Project

  1. Create Module:

    Next step is to create a Liferay Module Project.

Open File menu → click New → select Liferay Module Project. Provide project name as ‘FilterHook’ and click on ‘Next’.

Create Module

  1. Configure hook properties:

    Provide component name and package path for the filter class and click on Finish.

Configure hook properties

Now class FilterHook with package com.enprowess.filterclass is created in workspace module as follow,

FilterHook with package

  1. Implement Component:

    In class, you need to add following property inside @Component.

Implement Component

  1. Implement code:

    Please note that your filter class will extend BaseFilter class. You will need to override processFilter() method which will take parameters as HttpServletRequest request, HttpServletResponse response, FilterChain filterChain.Please see following piece of code.

Implement code

Now, you have filter hook ready to deploy in Liferay.

We at EnProwess believes in sharing knowledge to help open source community to grow. In my next post, I will talk about JSP hook. Till then happy learning!

Blog by,

Maitrik Panchal.

Notify of
Newest Most Voted
Inline Feedbacks
View all comments