Here I would like to explain about Hooks Plugin in liferay to customize property files , Jsp files & Listeners.
1. Hook Folder Structure
a. Go to plugins/hooks create a folder with any name. eg test-hook
b. Go to test-hook create folder docroot and build.xml file with this content.
<project name=”hook” basedir=”.” default=”deploy”>
<import file=”../build-common-hook.xml”>
</project>
c. Go to test-hook/docroot create folder with name WEB-INF.
d. Now under WEB-INF create a file liferay-hook.xml with below content:
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE hook PUBLIC “-//Liferay//DTD Hook 5.11.0//EN” “http://www.liferay.com/dtd/liferay-hook_5_2_2.dtd”>
<hook>
<custom-jsp-dir>/WEB-INF/jsps
</hook>
e. Create foler jsps under WEB-INF
f. Under jsps create folders html/portlet/<portlet_name>/xxx.jsp
——————————————————–
2. Customize JSP files
After creating the hook structure using above steps,
a) Under portlet_name create the same structure for the page which we want to modify.
Eg. If you want to modify the full_content.jsp inside assetPublisher portlet, path should be:
html/portlet/asset-publisher/display/full_content.jsp
b) Just give System.out.println(“Hooks customization”) inside that jsp file
c) ant deploy under plugins/hook.
d) Make sure that changes is affected in the server.
——————————————————–
3. Customize Property file
if you want to override portal-ext.properties file, just follow these steps
a) add the entry for property file inside liferay-hook.xml,
<hook>
<portal-properties>portal.properties</portal-properties>
<custom-jsp-dir>/custom-jsp</custom-jsp-dir>
</hook>
b) add any property inside portal.properties ( test-hook/docroot/WEB-INF/src)
c) ant deploy under plugins/hook.
d) Validate the changes
——————————————————–
4. Customize Model Listener
If you want to customize the any Model Listerner, you can follow these steps.
For Eg,
If you click Article Title from Asset Publisher portlet, one count views will be stored in TagsAsset table.
I want to do some changes in TagsAssetListener
a) set this property in this path, docroot/WEB-INF/src/portal.properties
value.object.listener.com.liferay.portlet.tags.model.TagsAsset = com.liferay.portlet.tags.model.TagsAssetListener
b) create TagsAssetListener.java in this path docroot/WEB-INF/src/com/liferay/portlet/Tags/Model
( Copy this model class from Liferay Portal Source)
TagsAssetListener.java
package com.liferay.portlet.tags.model;
import com.liferay.portal.model.BaseModelListener;
import com.liferay.portal.servlet.filters.cache.CacheUtil;
import com.liferay.portlet.tags.util.TagsUtil;
import com.liferay.portal.model.BaseModel;
import com.uson.stat.model.AssetAccess;
import com.uson.stat.model.impl.AssetAccessImpl;
public class TagsAssetListener extends BaseModelListener<TagsAsset> {
public void onAfterUpdate(TagsAsset tagsAsset) {
System.out.println(“Asset Id : >>>>> ” + tagsAsset.getAssetId());
System.out.println(“User Id : >>>>> ” + tagsAsset.getUserId());
System.out.println(“Total Views : >>>>> ” + tagsAsset.getViewCount());
}
}
c) ant deploy under plugins/hook.
d) Validate this by accessing one journal content article.
if you have any comments/query, you can shed you lights on this
- Gnaniyar Zubair
Tags: Hook
August 17, 2010 at 4:05 am |
Articles are created to express different body of knowledge. That is why I admire writers who are passionate of doing such incredible job. I salute you guys. By the way, I like you post for it is specifically talk about current issues and technicalities in life. I look forward for your subsequent post.I look forward for your next article.Thanks Marks Liferay Development
February 10, 2011 at 8:49 pm |
Regarding Properties file and hook..
How will I read the values of Property file inside a jsp in a hook I am getting errors.
urgent can some one reply quickly
February 22, 2011 at 6:48 pm |
String myPropertyValue = PropsUtil.get(“my.property”);
HTH
October 11, 2011 at 11:32 am |
Hi Gnaniyar,
Lets say i have one Portal.property in hook with custom proprty tag and value. Now i want to read this same property & values from property files. So i tried with PropsUtil.get(“test.property”); but it is always returning empty string. If you can explore more that would be really helpful.
October 11, 2011 at 11:34 am |
Sorry one correction in above post i want to read these custom property in my custom JSP which is inside hooks so is there any way?