Application Adpater Hook is one of the coolest feature in Liferay Portal. This type of Hook give a chance to customize look and feel for specific JSP in specific site. We can consider Application Adapter Hook as scope based JSP Hook. A JSP Hook changes jsp for the whole portal but an Application Adapter Hook changes JSP for specific site or site template. This article explain the basic use of Application Adapter Hook and its development.Â
Prerequisites: Before following this tutorial you should have knowledge onÂ
i) JSP Hook
ii) Liferay Site
iii) Site TemplateÂ
Note : To know Sites and Site Template go to liferay control panel. Under Sites column Sites and Site Templates are available.
Steps to create Application AdapterÂ
1. Create a liferay plugin project of type Hook.Â
2. Open liferay-hook.xml. This file should look like thisÂ
<?xml version="1.0"?> <!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.2.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_2_0.dtd"> <hook> <custom-jsp-dir>/custom_jsps</custom-jsp-dir> <custom-jsp-global>false</custom-jsp-global> </hook>
Note 1: custom-jsp-dir tag is used to tell liferay where is your customized jsp available in our Hook. Therefore under docroot custom_jsps is the folder contains our custom jsp.
Note 2: custom-jsp-global is false. This means that we are not going to modify the liferay original jsp. If its true then it will act like a normal Jsp Hook.Â
3. Copy any jsp from liferay source code . Here I simply copied view.jsp from navigation portlet.Â
4. Do some same changes in this file. That is view.jsp in the hook.Â
5. Deploy the Hook.Â
You have deployed the Hook. Now its time see the actual magic. To check whether everything working fine or not complete the below check pointsÂ
Action 1: Go to the liferay control panel and click sites.Â
Action 2. You will see many sites available. Click any one of it. In my case I have created one site called proliferay.Â
Action 3: Click Configuration then Site SettingsÂ
Action 4: In the settings page almost in the bottom you will seeÂ
This is the Application Adapter just we have created. In this case the name of the Application Adapter is “Application Adapter Hook“. This name is same as name of the war file which is deployed in the webapps directory. Just select the Application Adapter Hook from the drop down and save it.Â
Action 5: Now go to the site and add the Navigation Portlet. You should see the changes that you have done in your Hook. Keep in mind you should add Navigation portlet in the same site where you have applied the Application Adapter Hook.Â
Action 6: Now go to any other site where you have not applied Application Adapter Hook. Add the same Navigation portlet there also. This time you should not see the changes of the JSP that you have done in the Hook.
Action 7. Similarly explore the Site Templates also.Â
The Key Point:
The site where we have applied the Application Adapter Hook  for that site only we should see the changes for the Navigation portlet.
Differences between JSP Hook and Application Adapter Hook:
Difference 1: JSP Hook is for entire portal. But Application Adapter Hook is not for entire portal. It has scope to specific site.Â
Difference 2: In JSP Hook we don’t use custom-jsp-global tag. But Application Adapter Hook we require it.Â
Difference 3: When a JSP Hook is deployed the original file gets modified. The original file is renamed as origianl-name.portal.jsp.For example view.portal.jsp. But in case of Application Adapter Hook the original file remains the same. Instead it creates new jsp file like original-name.name-of-the-adapter.jsp. For example view.application-adapter-hook.jsp.Â
Hi Hamidul,
Very informative post. However I would like to add few of my findings while working with adapters.
1. You can not customize Liferay taglib jsps using adapters.
2. If you are customizing a jsp which is being referred by another jsp using tag then, you have to update that jsp to include our customized jsp.
Hi Hamidul,
Thanks for for the tutorial, this is really nice one for me to learn HOOKs.
Adapters are good, until you discover that most of things are tricky and they don’t apply as expected, as stated by Pande, taglib and nested jsps are the most common things you would customize per site.
As I know, taglib should be working, but in 6.2 there’s a bug in the IncludeTag class. There’s a temporary fix (you need to recompile though).
Hi Hamidul , how to achieve same in liferay DXP