• Liferay Application Adapter Hook

    Posted on December 10, 2014 by Hamidul Islam in Liferay.

    sites


    aimApplication 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. 

    application-adapter-directory

    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 

    application-adapter-selection

    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 

    Post Tagged with , ,

4 Responses so far.

  1. Rahul Pande says:

    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.

  2. Ajit says:

    Hi Hamidul,

    Thanks for for the tutorial, this is really nice one for me to learn HOOKs.

  3. mizar says:

    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).

  4. Tahir says:

    Hi Hamidul , how to achieve same in liferay DXP

Leave a Reply

Your email address will not be published. Required fields are marked *

Are you human? * Time limit is exhausted. Please reload CAPTCHA.

Top
%d bloggers like this:

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close