Tuesday, 30 June 2015

How to modify/override default value of Liferay's property

Liferay controls many things via properties and it supports to override the value of the portal.properties file.
There are two ways available to override portal.properties file.
1) Using portal-ext.properties
2) via Hook.

Lets see how can we override liferay properties via hook.

There are three simple steps to achieve it:

1)  Modify "lieray-hook.xml" to provide support for "properties" file
2)  Create the "portal.properties" file inside "src" folder of the Hook project
3)  Deploy and verify changes

Lets look at the steps in detailed:

1)  Modify "lieray-hook.xml" to provide support for "properties" file
    <hook>
        :
        <portal-properties>portal.properties</portal-properties>
        :
    </hook>
 
    We have specified the file which should be used to override existing liferay properties
 
2)  Create the "portal.properties" file inside "src" folder of the Hook project

Lets say we like to call perform some action before user logs in. That is being controlled by the property called "login.events.pre".

Here is the entry you need to write inside "portal.properties" file.
login.events.pre=com.student.CheckRegistration

So "CheckRegistration" will be called before student/user logs in.

 
3)  Deploy and verify changes

    Once changes are done we need to deploy our Hook project and upon next time login your custom class will be triggered before student login.
 
Note:
   1) If you like to know what all properties can be override using Hook you need to check "liferay-portal-src-6.*\definitions\liferay-hook_6*.dtd"
   2) If you like to know what is the default value of the property you override you can check it on location "\liferay-portal-src-6*\portal-impl\src\portal.properties"
 
 
Cheers!
Henal Saraiya
(Senior Consultant)
CIGNEX Datamatics

No comments:

Post a Comment