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.. :)
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.2.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_2_0.dtd"> | |
<hook> | |
<portal-properties>portal.properties</portal-properties> | |
</hook> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
value.object.listener.com.liferay.portlet.journal.model.JournalArticle=me.rkg.hooks.model.JournalArticleListener |
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package me.rkg.hooks.model; | |
import com.liferay.portal.ModelListenerException; | |
import com.liferay.portal.kernel.util.LocaleUtil; | |
import com.liferay.portal.model.ModelListener; | |
import com.liferay.portlet.journal.model.JournalArticle; | |
public class JournalArticleListener implements ModelListener<JournalArticle> { | |
@Override | |
public void onAfterAddAssociation(Object classPK, | |
String associationClassName, Object associationClassPK) | |
throws ModelListenerException { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void onAfterCreate(JournalArticle model) | |
throws ModelListenerException { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void onAfterRemove(JournalArticle model) | |
throws ModelListenerException { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void onAfterRemoveAssociation(Object classPK, | |
String associationClassName, Object associationClassPK) | |
throws ModelListenerException { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void onAfterUpdate(JournalArticle model) | |
throws ModelListenerException { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void onBeforeAddAssociation(Object classPK, | |
String associationClassName, Object associationClassPK) | |
throws ModelListenerException { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void onBeforeCreate(JournalArticle model) | |
throws ModelListenerException { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void onBeforeRemove(JournalArticle model) | |
throws ModelListenerException { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void onBeforeRemoveAssociation(Object classPK, | |
String associationClassName, Object associationClassPK) | |
throws ModelListenerException { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void onBeforeUpdate(JournalArticle model) | |
throws ModelListenerException { | |
// TODO Auto-generated method stub | |
} | |
} |
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.