Share

Customizing Sites and Site Templates with Application Adapters

if you need to customize specific sites without propagating the customization throughout the entire portal then use Application Adapters.

Purpose

By default,When we customize the JSP files through the hooks,changes applied globally to all liferay sites.For site specific jsp file customization,Liferay provides a very strong feature called application adapter.
To restrict JSP customization to specific site or site template add the following code snippet to the liferay-hook.xml

<hook>
     <custom-jsp-dir>/META-INF/custom_jsps</custom-jsp-dir>
     <custom-jsp-global>false</custom-jsp-global>
</hook>

How to create an Application Adapter

1. Create a Hook Project
2. Open liferay-hook.xml under docroot/WEB-INF/liferay-hook.xml
3. You can have the overview of the liferay-hook.xml as follows.In this select Custom Jsps folder from the              outline pallet to bring up the custom jsps option



4. Select the checkbox Customize Liferay Portal JSPs and create the default custom JSP folder 
  /META-INF/custom_jsps by clicking the icon that has the three yellow diamonds.By clicking 
    this icon it will create custom_jsps folder under META-INF of our project.It is as follows


5. Now add the existing JSP page of portal which you want to customize by clicking the plus icon(+).
    Here we chosen  html/portlet/navigation.jsp and click on source(Highlighted by Red color in the image             below) view at bottom left of the xml file.


6. Add the following code snippet to the liferay-hook.xml

<hook>
     <custom-jsp-dir>/META-INF/custom_jsps</custom-jsp-dir>
     <custom-jsp-global>false</custom-jsp-global>
</hook>

   To turn the hook’s global custom JSP setting off put the value of <custom-jsp-global> to false.
7. This step is important.If you observe the xml file it is not yet saved.So Please save the file by 
    clicking ctrl+s.
8.Open docroot\META-INF\custom_jsps\html\portlet\login\navigation.jsp file and add the following code

<%@ taglib uri="http://liferay.com/tld/util" prefix="liferay-util" %>
<liferay-util:include page="/html/portlet/navigation/view.jsp" useCustomPage="false" />
<p>
This was modified by the Sample Application Adapter.
</p>

For Application adapter hooks include the original jsp by including <liferay-util:include page> tag's
useCustomPage attribute to false.Do not include the jsp like appending the suffix .portal.jsp to the original file name.Appending the suffix is only applicable for global hooks.

9. Deploy Application adapter Hook plugin.
10. Open liferay portal instance

Test Case

1.Create two sites
       SiteWithApplicationAdapter
             a)  Goto ControlPanelàSiteàClick on AddàBlank Site
    b)   Give Site name as SiteWithApplicationAdapter
             c)  Click on Save,It will navigate to the Site Settings as follows.
                  ScrollDown,In the configuration you can select the Application Adapter with your hook                        name(SampleApplicaationAdapter)

      WithOutApplicationAdapter
          Follow the same steps but do not select ApplicationAdapter.
2. Create two pages for every site then only you can see and navigate to created sites to see the output.
3. Add the Navigation portlet in one of the pages created for each site
4. Now Observe the results by accessing two urls
     http://localhost:8686/web/sitewithoutapplicationadapter/home
   
 
    http://localhost:8686/web/sitewithapplicationadapter/home


Congratulations !!!


No comments:

Post a Comment