Today we will discuss about Custom Action Hook in Liferay. In portal.properties file their are some properties which have multiple values and some have only one value like true/false.
a)For single value like true/false we override the property see
Portal Properties hook in Liferay.
b)For multiple values properties like application.startup.events any values you specify in a hook don’t override the list defined in the portal, but rather are appended to that list.Your actions will then fire when Liferay Portal starts in addition to the list of actions that are specified in the default Liferay installation
In liferay there are some portal events you can see those events in portal.properties.
These events are:-
- application.startup.events
- application.shutdown.events
- login.events.pre
- login.events.post
- logout.events.pre
- logout.events.post
- servlet.service.events.pre
- servlet.service.events.post
- servlet.session.create.events
- servlet.session.destroy.events
The action of these events are defined in portal.properties so we need to extend portal.properties to create a custom action.
So lets start step by step:-
Step 1:-Create Liferay hook project
File-->New-->Liferay Plugin Project-->Provide name-->Select hook in plugin type-->Finish.
You can see snapshot in step 2 of Portal Properties Hook in Liferay
Step 2:-Create hook inside project
Right click on project-->New-->Liferay hook Configuration-->tick portal.properties-->Next.
then this pop up is open:-
Select login.events.pre and click ok.Now Click on New button of previous figure to add our class as:-
Provide Classname, java package and select superclass as Action and click ok.
Now Ok and finish.This will create portal.properties file automatically also provide entry in liferay-hook.xml.
Step 3:-Check Generated Code
By using eclipse ide portal.properties file automatically created as:-
portal.properties
and liferay-hook.xml as:-
liferay-hook.xml
Step 4:-Provide your custom code
Open MyCustomLoginAction.java from package com.test and paste this code:-
MyCustomLoginAction.java
Step 5:-Check Output
Now deploy your hook and login to liferay as soon as you login the eclipse console shows:-
My Login Pre event
Project Structure
You can Download Source code from Custom Action Hook in Liferay
Hope this will Help....
Related Post:-
No comments:
Post a Comment