Published using Google Docs
LIFERAY TUTORIAL - HOOK PLUGIN (Customize Jsp).docx
Updated automatically every 5 minutes

LIFERAY TUTORIAL

notarazi.blogspot.com

LIFERAY TUTORIAL – HOOK PLUGINS (HOOKING JSP)

INTRODUCTION

Hook allows customizing Liferay Default settings. In this tutorial, a javascript file “full_content.jsp” will be modified to demonstrate the customization effect.

PRE-REQUISITE

This tutorial is based on the following platform:

  1. Liferay 6.1
  2. Eclipse Indigo
  3. Tomcat 7

SUMMARY OF STEPS

The following steps will create a hook for the full_content.jsp ( full path: html/portlet/asset-publisher/display/full_content.jsp). The output package will be installed to {TOMCAT_ROOT}/Webapps/.

STEPS

  1. As an initial preparation, goto to Liferay portal and Add/Asset Publisher.
  2. Add New “Web Content”. Publish the content.

  3. The Content Title appears on the portlet as follows:

  4. If “Read More” is clicked, the following is shown. Take note of the text “Web Content Title”. (You may want to compare the following image against the one in Step 14.)

  5. Now a new hook “Hook-FullContent” will be created. Goto Eclipse menu File/New/Liferay Project. Type Project Name “Hook-FullContent”. Select “Hook”. Click “Finish”. A new hook plugin project will appear in Package Explorer panel.

  6. Goto Package Explorer panel. Explode the “Hook-FullContent-hook” package. Select docroot/WEB-INF/liferay-hook.xml.


  7. Open the file.

  8. Create Custom Hook Folder “/WEB-INF/jsps”.
    Using
    Hook Configuration” tab, edit as follows.


    Alternatively, using “Source” Tab, enter the (blue)  code as follows. SKIP TO STEP 10 AND MANUALLY CREATE THE FOLDER STRUCTURE/PATH ACCORDING TO STEP 10:
    <?xml version="1.0"?>
    <!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.1.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_1_0.dtd">
    <hook>
       <custom-jsp-dir>/WEB-INF/jsps</custom-jsp-dir>
    </hook>
  9. Add the JSP file to be modified.


    Save the “liferay-hook.xml” file. The system will automatically create the file, folders and path in the “jsps” folder.
  10. Goto Package Explorer panel, find the jsp file and open the file.


  11. Find the line...
    String title = (String)request.getAttribute("view.jsp-title");
    ... and change to...
    String title=”Hooked Title”;

    Save the changes.


  12. Deploy the hook. (Select the package, right-hand click, select Liferay/SDK/Deploy)

  13. Observe Console Window Output:

  1. Compare to Step 4. The title has changed to “Hooked Title”.

  2. To remove the package, delete it in the Package Explorer panel. This will make it undeployed from the server. But, if this doesn’t work, the plugin can be manually deleted from the {TOMCAT _ROOT}/webapps folder. After the plugin is removed, the effect will be stored back to the Step 4.


DOWNLOAD

https://sites.google.com/site/notarazi/home/liferaydocs/sample-Hook-FullContent-portlet.zip

REFERENCES:

http://zubairwiki.wordpress.com/2010/02/23/playing-with-hooks/#more-127

http://kamalkantrajput.blogspot.com/2009/05/using-hooks-in-liferay-for-customizing.html