Showing posts with label Liferay 7 Hook. Show all posts
Showing posts with label Liferay 7 Hook. Show all posts

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

Friday, 12 August 2016

Creating Liferay JSP hook with Liferay 7

Creating Liferay JSP hook with Liferay 7
Liferay 7 doesnt support the hook, as all of the bundles are generated using the OSGI. In OSGI you need to create a fragment and attach the same with the Orginal module. By this we can chnage the existing JSPs in the module.
Liferay IDE as of now doesnt supooort the direct creation of the hook.  So we need to create the hook project using blade and then we can go ahead and do rest of the stuff using the IDE.
Also point to keep in mind is that Liferay 7 GA2 is having a bug due to which theJSP hooks are not getting deployed in the liferay. For further information on that you can go ahead and have a look on this issue https://issues.liferay.com/browse/LPS-66814.
So in this tutorial we will be using the Liferay 7 GA 1.
Following is the command to create a blank project for JSP hook
blade create -t fragment -h <HOST_BUNDLE_SYMBOLIC_NAME> -H <HOST_BUNDLE_VERSION> <PROJECT_NAME>
HOW TO CREATE JSP HOOK IN LIFERAY 7 USING FRAGMENTS TEMPLATE
Step 1 -> Find the value for -h i.e the Host bundle Symbolic name. Open the GOGO shell  as in the below figure
And type lb
This will list down all of the modules/bundles running in that particular server. As we are working on the login jsp hook. we can find the login modules by writing the following command
lb | grep Login

Here the list of all of the Login modules. Now we are interested in the Login Web module.  Modules are listed in the following fashion
BUNDLE_ID | STATUS  |LEVEL |NAME (VERSION)
We can see that Lifeary Login Bundle with Bundle ID 371 is active and is of version (1.0.3).
So now we need to find out the  HOST_BUNDLE_SYMBOLIC_NAME and the HOST_BUNDLE_VERSION in order to create a fragment.
We can get the further details of the bundle by using the command b <BUNDLE_ID>
so we will punch in b 371 this will give us the complete details of the bundle.
We can see that first line is com.liferay.login.web_1.0.3[371], this will give the desired result that we are seeking.
com.liferay.login.web -> HOST_BUNDLE_SYMBOLIC_NAME
1.0.3 -> HOST_BUNDLE_VERSION
So now we are having all of the required details so that we can create a JSP hook for login portlet.
Goto the workspace's module folder  that you have created and punch in the following command.
F:\LR7\wokspace\FirstWorkspace\modules>blade create -t fragment -h com.liferay.login.web -H 1.0.3 my-login-jsp-hook

This will create a blank project in the module folder.
Now we need to copy down the JSPs from the login module which we want to change. To do that import the source  of liferay into eclipse and go to the
/portal-master/modules/apps/foundation/login/login-web/src/main/resources/META-INF/resources
Now copy down the required jsps and paste them into the project that we had just created.
So the result will be something like this

Now customize the changes in the login.jsp  and post that deploy the project


Once deployed you can see that the changes are reflected in the portal as shown below


For more details on the above topic please go through the below video on my youtube channel.

RELATED POSTS

 

Copyright @ 2016 LiferayRevisited.