You implement a model listener with a hook. Hooks and model listeners are described in the wiki post I linked to. Also, take a look at the SevenCogs hook that comes with your Liferay bundle to get a more handson grip on how hooks are used.
One thing has changed since Ray wrote the wiki post:
Now you don't register your model listener in the liferay-hook.xml file. You rather specify your model listener in a portal.properties file, and then register the portal.properties file in the liferay-hook.xml file.
1. To register a model listener - create a portal.properties file in your hook and specify your listener:
1value.object.listener.com.liferay.portlet.documentlibrary.model.DLFileEntry=my.package.hook.listeners.DLFileEntryListener
2. Add your portal.properties to your liferay-hook.xml file:
1<hook>
2 <portal-properties>portal.properties</portal-properties>
3</hook>
3. Add your new listener class to your hook:
1package my.package.hook.listeners;
2import com.liferay.portal.ModelListenerException;
3import com.liferay.portal.model.BaseModelListener;
4import com.liferay.portlet.documentlibrary.model.DLFileEntry;
5
6public class DLFileEntryListener extends BaseModelListener<Group> {
7
8 public void onAfterCreate(DLFileEntry entry) throws ModelListenerException {
9
10 // The code you wish to be executed when a new entry has been made
11
12 System.out.println("A new document library entry was created");
13
14 }
15
16}
Hooks can be tricky to get at first. But play around with them for a while. Learning how they work unveils a lot of possibilities in Liferay.
Cheers,
Erik
Please sign in to flag this as inappropriate.