Site icon Pro Liferay

Liferay Application Adapter Hook

sites


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

Download Source Code 

Exit mobile version