Wednesday, March 4, 2015

[Liferay] Model Listener hook in 6.2

If you are looking for help to create a model listener hook in Liferay 6.2 here are the simple steps to walk you through.

Step 1. Create a simple hook in plugins sdk. Go to plugins-sdk > hooks directory and run the command below.

create journal-article "Journal Article hook"


Step 2. Once the hook is created you should be able to see the default directory structure created for a hook. Now we need to add a portal.properties file to our hook and make an entry to liferay-hook.xml.

Step 3. And we create a portal.properties file in \docroot\WEB-INF\src and put the line below.

If you are creating for another model, change the file accordingly. You can also add multiple entries in case you are implementing for multiple models.

Step 4. Now we create the file we mentioned in portal.properties. In our case the package is me.rkg.hooks.model and class name is  JournalArticleListener.

This class implements ModelListener<T> as you can see in the gist above. All methods above are stub implementation of ModelListener interface methods.

Assuming that you knew what is the use of Model Listner hook, not covering that here. Implement the logic in methods you need to use.

Hope this helps.

Until next time.. :)


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.