Today we will see how to create Model Listener in Liferay 6.2 .I write Listener for Web Content ie Journal Article .So when a Journal Article is created we will do some processing.
so lets start this Step by Step:-
Project Structure
Step 1:-Create a hook project
Right Click in Project Explorer and Click New -> Liferay plugin project. Now give the Project name and select hook in plugin type:-
and Click Finish.
Step 2:-Create properties file
Now create a portal.properties file inside src and paste this :-
Explanation:-
Here we mention that we want to listen JournalArticle . You can also use other models like User,UserGroup etc.
The syntax is:-
value.object.listener.FullpathofModel.
And after equal sign(=) we mention full path of our Custom Class .
The syntax is:-
value.object.listener.FullpathofModel.
And after equal sign(=) we mention full path of our Custom Class .
Step 3:-Create our Custom Class
Create a class MyJournalArticleListner inside com.mylistner package as mention in portal.properties file:-
Explanation:-
1)Our Class must Extend BaseModelListener<JournalArticle>
2)BaseModelListener class contain various methods which you can override here i use two methods onBeforeCreate and onAfterCreate.
2)BaseModelListener class contain various methods which you can override here i use two methods onBeforeCreate and onAfterCreate.
Step 5:-Entry in liferay-hook.xml
Open liferay-hook.xml and provide the entry of portal.properties file:-
Step 6:-Check Output
Step 6:-Check Output
Now Create a basic web Content as soon as you click on publish it will display the message on console :-
Before Create=>11448
After Create=>11448
Before Create=>11448
After Create=>11448
You can download the source code from here.
Hope this will Help....
Related Post:-
Basic web content in Liferay
Categorization in web content
Structure and Template in Web Content
Fetch Web Content Programmatically
Get Journal Article Using SAX Parser
Form Handling in Spring Portlet
Embedding a Web Content in a Portlet
Fetch Latest Version Journal Article or Web Content in Liferay
Hope this will Help....
Related Post:-
Basic web content in Liferay
Categorization in web content
Structure and Template in Web Content
Fetch Web Content Programmatically
Get Journal Article Using SAX Parser
Form Handling in Spring Portlet
Embedding a Web Content in a Portlet
Fetch Latest Version Journal Article or Web Content in Liferay
No comments:
Post a Comment