Thursday, May 28, 2009

Using Hooks in Liferay for customizing jsp

Using hooks customizing jsp page of a existing liferay portlet.

In this example I am taking portlet asset-publisher.

Step 1: Go to plugins/hooks create a folder with any name. eg asset-publisher-hook
Step 2: Go to asset-publisher-hook create folder docroot and build.xml file.
Content of build.xml should be like this:


<project name="hook" basedir="." default="deploy">
<import file="../build-common-hook.xml">
</project>




Step 3: Go to asset-publisher-hook/docroot create folder with name WEB-INF.
Step 4: Now under WEB-INF create a file liferay-hook.xml and a folder with name jsps.
Step 5: In liferay-hook.xml write following code.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 5.1.0//EN" "http://www.liferay.com/dtd/liferay-hook_5_2_2.dtd">

<hook>
<custom-jsp-dir>/WEB-INF/jsps </hook>




Step 6:Under jsps create folders html/portlet/portlet_name in our case portlet_name is asset-publisher.
Step 7:Under portlet_name create the same structure for the page which we want to modify.
Eg. In asset-publisher we will try to modify full_content.jsp then structure will be

html/portlet/asset-publisher/display/full_content.jsp

Step 8:Customize the jsp file.
Step 9:Go to plugins/hook
Do ant deploy
Step 10:Check the changes on server