Friday 23 September 2016

How to Hook a liferay Action Command in Liferay 7 DXP?

How to Hook a liferay Action Command in Liferay 7 DXP?
In this tutorial we are going to see how we can hook an action command in liferay. In the previous tutorials we had seen how we can write a portlet filter and how we can use model listeners in liferay.
We are going to hook the LoginActionCommand in this tutorial.  
To hook a liferay action follow the following steps -:
First we need to find the name of the module for which we need to hook the action. In this case it is Login portlet.
To do this type lb | grep Login in the GOGO Shell command.
This will yield multiple results which contain the Login as the module name. Something like below.




Liferay login web is the one which we are interested in. We can see that the Liferay login Web is having the version 1.0.7. We will need this value going forward.
To view the detail of the above module, type the following command in the gogo shell comand.


b 220   this will give out the details of the above module. Something like below.


Pull out the compelete name of the module as in the above highlighted figure. which would be
com.liferay.login.web
We would be using this to import the Java classes.
From the details of the module extract the path that you need to hook. In our case it is /login/login


The details  are as follows
{com.liferay.portal.kernel.portlet.bridges.mvc.MVCActionCommand}={mvc.command.name=/login/login, javax.portlet.name=[com_liferay_login_web_portlet_FastLoginPortlet,com_liferay_login_web_portlet_LoginPortlet], component.name=com.liferay.login.web.internal.portlet.action.LoginMVCActionCommand, component.id=1156, service.id=610, service.bundleid=220, service.scope=bundle}


In bold are the details that we need to ovverride/hook the ActionCommand.


Once we are having the above details we can use these to create a class that will ovveride the ActionCommand. This can be included in any type of module while creating from eclipse.


We need to specify the above details in the properties of component


@Component(immediate = true, property = { "javax.portlet.name=com_liferay_login_web_portlet_FastLoginPortlet",
"javax.portlet.name=com_liferay_login_web_portlet_LoginPortlet", "mvc.command.name=/login/login",
"service.ranking:Integer=700" }, service = MVCActionCommand.class)

NOTE - : The service.ranking:Integer=700 should be higher number than that of service.id which was 610 in our case.


The complete code for the Hook is given below.



The result will be a message printed in the console.


For more information on the above topic you can visit my youtube channel

 

Copyright @ 2016 LiferayRevisited.