Saturday, June 17, 2017

Model Listener in Liferay 6.2


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 .

 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.





Step 5:-Entry in liferay-hook.xml

Open liferay-hook.xml and provide the entry of portal.properties file:-



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


No comments:

Post a Comment

Total Pageviews

Number Of Unique Visitor

Free counters!