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

17 comments:

Unknown said...

This is great kamal kant , realy it's very useful for us keep updating your knowledge.

Liferay said...

Oh!! great.. I got the solution from your blog. Thank you Kamal Kant. Its fantastic.

Anonymous said...

How do you unregister a hook? I deployed one, but I realized I needed to make the changes in the ext instead to get some deeper functionality. But, now when I deploy the ext changes, the hook overlaps and breaks it. Do you know how I can remove the hook? Thanks for any insight you can provide!

Anonymous said...

Thanks, it works.

For absolute beginners: First you have to checkout Liferay's plugin-SVN project ... which is the root for the described Step 1.

"do ant deploy" means: you have to start ant which is a build-tool. But if you get problems at this point (I really found this question!), you are really standing at the very beginning of developping. Perhaps you should better ask someone to do this for you.

Anonymous said...

Its very useful and given in a very detailed fashion.... Thanks...

Anonymous said...

i tried this and it works, i was able to modify any page under under webapps/ROOT/html/.... for example I i customized welcome.jsp under webapps/ROOT/html/portlet/welcome....
what my question is that can i use this approach to modify any page under webapps/...because i want to modify a portlet which resides under webapps/myportlet/....

Unknown said...

thank you...
I have created all the steps working very well but the last step whwnever i am trying to deploy the hook on my Liferay 5.2.3 server using ant deploy it shows the error as

C:\Liferay Plugins SDK\build-common-plugins.xml:49: The following error occurred
while executing this line:
C:\Liferay Plugins SDK\build-common-plugins.xml:69: The following error occurred
while executing this line:
C:\Liferay Plugins SDK\build-common-plugins.xml:80: The following error occurred
while executing this line:
C:\Liferay Plugins SDK\build-common-plugins.xml:55: The following error occurred
while executing this line:
java.io.FileNotFoundException: C:\Liferay Plugins SDK\hooks\customjsp-hook\build
.xml (The system cannot find the file specified)

so please tell the solution mail me on

umesh_annegirikar007@yahoo.co.in
umesh.annegirikar@shalaka.com

Unknown said...

Hi Umesh ,
I think you are giving command ant deploy from wrong place see where is build.xml from there you to give ant deploy.

test said...

Hi KamalKant,

You missed this step
under WEB-INF create a file copy any liferay-plugin-package.properties and paste here (you will find this file in themes under WEB-INF)

Unknown said...

I am looking for such type of informative news and i get through this blog so i am very much thankful to you for sharing such a great information.
- liferay portlet

Lalit Jugran said...

Thank you,for this blog sir

the above example is to the point & it clearly explained me the functionality of hook in liferay.

Krishna Gaur said...

hahahahah

Anonymous said...

this is cool!

anilkumar said...

thanks a lot kamal for spending your valuable time on this knowledge sharing....Anil Sunkari

Anonymous said...

Hi
I am also looking answer to the same question mentioned below:

what my question is that can i use this approach to modify any page under webapps/...because i want to modify a portlet which resides under webapps/myportlet/....

Unknown said...

yes you can

Ajit Kumar said...

i want to know how to
modify any page under webapps/...because i want to modify a portlet which resides under webapps/myportlet/....