Learn Liferay DXP Struts Action Hook in 4 simple steps


April 27, 2022

Welcome to our “How To?” series of post. In this series, we are talking about different development concept in Liferay DXP/7. In this post, I am going to talk about Struts Action Hook.

Liferay offers following list of hooks to override default behaviour of out-of-the-box features,

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

Many Liferay portlets are implemented using Struts. If you want to change the behaviour of existing portlet you certainly need a mechanism to override its action class. Struts Action hook is used to override existing struts action. Struts action hook help you to achieve it.

Here I assume that you have already read previous posts and installed JDK1.8, Liferay 7/DXP and IDE. These are the prerequisite to proceed with implement Struts action hook.

Now let’s understand the steps to implement struts action hook.

  1. Create Liferay WorkSpace Project


To create a Liferay Workspace in IDE follow this:

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

Create Liferay WorkSpace Project

  1. Create Liferay Module Project


You need to create module project for Struts Action hook. Following are the steps to create module,

Click on File menu → Click New → Select Liferay Module Project and provide project name as StrutsActionHook and click next. See following screenshot for your reference,

Create Liferay Module Project

Provide appropriate class name and package name for the class. For this example, I am providing class name as UpdateEmailStrutsAction.

Provide appropriate class name and package name

After you finish the wizard, you should see project structure in eclipse as follow,

 project structure

  1. Implement Component


You successfully created project structure. Now it’s time to implement business logic to update email address. Implement @Component as follow in class,

Implement Component

  1. Override execute method


Ensure that your class extends BaseStrutsAction class. To implement business logic override, execute() method as follow,

Override execute method

Congratulation! You successfully implemented struts hook. Now let’s quickly understand what you exactly implemented.

In @Component, you configured struts action i.e. ‘/portal/update_email_address’ to instruct container that when user trigger action to update email, please execute business logic mentioned in my class.

In case you want to override different action then mentioned in this example, You can see ‘struts-config.xml’ file to know all out-of-the-box struts actions. You can find this file on following path in your IDE.

tomcat server → liferay-ce-portal-7.0-ga3 → tomcat-8.0.32 → webapps → ROOT → WEB-INF → struts-config.xml.

I hope this post will help you to implement struts hook easily in Liferay DXP. In my next post, I will share ‘How to?’ steps for different implementation in DXP, till then keep learning!

Blog by,

Maitrik Panchal

Notify of
Inline Feedbacks
View all comments