Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Liferay 6.1 : How to associate Listener in my case ?? Kiran Jai July 31, 2012 7:53 AM
RE: Liferay 6.1 : How to associate Listener in my case ?? Jay Patel July 31, 2012 8:11 AM
RE: Liferay 6.1 : How to associate Listener in my case ?? David H Nebinger July 31, 2012 8:23 AM
RE: Liferay 6.1 : How to associate Listener in my case ?? Kiran Jai July 31, 2012 8:24 AM
RE: Liferay 6.1 : How to associate Listener in my case ?? Jay Patel August 1, 2012 7:56 AM
RE: Liferay 6.1 : How to associate Listener in my case ?? clint barbosa August 23, 2012 3:27 AM
RE: Liferay 6.1 : How to associate Listener in my case ?? David H Nebinger August 23, 2012 5:27 AM
RE: Liferay 6.1 : How to associate Listener in my case ?? clint barbosa August 23, 2012 7:45 PM
RE: Liferay 6.1 : How to associate Listener in my case ?? Richard Tichy September 3, 2012 7:50 AM
RE: Liferay 6.1 : How to associate Listener in my case ?? Richard Tichy September 3, 2012 8:15 AM
RE: Liferay 6.1 : How to associate Listener in my case ?? David H Nebinger September 3, 2012 8:47 AM
RE: Liferay 6.1 : How to associate Listener in my case ?? Richard Tichy September 4, 2012 12:35 AM
RE: Liferay 6.1 : How to associate Listener in my case ?? Richard Tichy September 4, 2012 2:16 AM
RE: Liferay 6.1 : How to associate Listener in my case ?? Tanaji Londhe November 4, 2012 11:52 PM
RE: Liferay 6.1 : How to associate Listener in my case ?? Rubén Romero Montes November 21, 2012 7:40 AM
RE: Liferay 6.1 : How to associate Listener in my case ?? Martin Wiegand August 7, 2014 7:01 AM
RE: Liferay 6.1 : How to associate Listener in my case ?? David H Nebinger August 7, 2014 7:03 AM
RE: Liferay 6.1 : How to associate Listener in my case ?? Martin Wiegand August 7, 2014 7:15 AM
RE: Liferay 6.1 : How to associate Listener in my case ?? David H Nebinger August 7, 2014 8:23 AM
RE: Liferay 6.1 : How to associate Listener in my case ?? David H Nebinger August 7, 2014 6:48 AM
RE: Liferay 6.1 : How to associate Listener in my case ?? Debopam Mitra September 3, 2014 5:20 AM
RE: Liferay 6.1 : How to associate Listener in my case ?? David H Nebinger September 3, 2014 6:55 PM
RE: Liferay 6.1 : How to associate Listener in my case ?? Debopam Mitra September 3, 2014 10:44 PM
RE: Liferay 6.1 : How to associate Listener in my case ?? Debopam Mitra September 4, 2014 2:52 AM
RE: Liferay 6.1 : How to associate Listener in my case ?? David H Nebinger September 4, 2014 9:18 AM
RE: Liferay 6.1 : How to associate Listener in my case ?? Debopam Mitra September 7, 2014 11:38 PM
RE: Liferay 6.1 : How to associate Listener in my case ?? David H Nebinger July 31, 2012 8:18 AM
Kiran Jai
Liferay 6.1 : How to associate Listener in my case ??
July 31, 2012 7:53 AM
Answer

Kiran Jai

Rank: Junior Member

Posts: 38

Join Date: April 9, 2012

Recent Posts

Hi ,

I am using Liferay 6.1 CE for Portal Application development .
I am new to Liferay , so please excuse if my question is wrong .

My query is with respect to the Listeners , I see that Liferay Listeners are limited to predefined
core portal model like journal , users --- etc . (Correct me if i am wrong)

I want to call this Listener on onAfterCreate method ( taht is after creating the User is done )

In our Aplication for creating user , we have a Seperate createUser.jsp , and on click of the submit button , it is stored in one of the Table called Virte_Users table in Database .

Please let me know , Is it possible to associate Listener in my case ?? Thanks in advance .
Jay Patel
RE: Liferay 6.1 : How to associate Listener in my case ??
July 31, 2012 8:11 AM
Answer

Jay Patel

Rank: Regular Member

Posts: 116

Join Date: February 23, 2010

Recent Posts

Hi Kiran,

AFAIK, model listerners are for Core entities only, but still I am not able to understand following items:

1. Why you are storing users in your custom table because all other tables/entities use userId from user_ table of Liferay?

2. And if there is really need to use custom user table then I guess there is no need to have listeners as you will always have control over the logic which stores data in custom table user table, right?

3. The listeners on Core entities like User, Journal etc. were created so that changes in the Liferay core code can be minimal just in case if we want to do additional operations when changes happen to these Core entities.

-Jay.
David H Nebinger
RE: Liferay 6.1 : How to associate Listener in my case ??
July 31, 2012 8:18 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 7238

Join Date: September 1, 2006

Recent Posts

Kiran Jai:
I see that Liferay Listeners are limited to predefined core portal model like journal , users --- etc . (Correct me if i am wrong)


You are wrong. Listeners can be added to any ServiceBuilder-based entity (it just so happens that all portal models are SB-based).

In our Aplication for creating user , we have a Seperate createUser.jsp , and on click of the submit button , it is stored in one of the Table called Virte_Users table in Database. Please let me know , Is it possible to associate Listener in my case ?? Thanks in advance .


As long as you used SB to handle your entities, you would declare a model listener for them in the exact same way you would for a core portal model.

If you did not do things the Liferay way and rolled your own persistence layer, then it is up to you to implement the listener class also.
David H Nebinger
RE: Liferay 6.1 : How to associate Listener in my case ??
July 31, 2012 8:23 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 7238

Join Date: September 1, 2006

Recent Posts

Jay Patel:
AFAIK, model listerners are for Core entities only


Wrong. See my other post in this thread.

1. Why you are storing users in your custom table because all other tables/entities use userId from user_ table of Liferay?


Jay is absolutely right here. You must invoke the normal Liferay processes for user management or you will totally break the functionality of the portal.

2. And if there is really need to use custom user table then I guess there is no need to have listeners as you will always have control over the logic which stores data in custom table user table, right?


Not entirely true. Listeners are invoked when the service is called by any plugin, whether it's the one you've created or some other plugin that is invoking your service classes. There are definite use cases where adding listeners to trigger activities makes sense even in your own code, i.e. your own custom auditing process or something.

3. The listeners on Core entities like User, Journal etc. were created so that changes in the Liferay core code can be minimal just in case if we want to do additional operations when changes happen to these Core entities.


Again they serve other use cases as well. The Liferay EE auditing mechanism is based on model listeners. The LDAP export is also plugged in this way, I believe. The model listeners can be used in many cases where you want to ensure some activity is invoked regardless of where the origination of the request came from (i.e. a core portlet or your own).
Kiran Jai
RE: Liferay 6.1 : How to associate Listener in my case ??
July 31, 2012 8:24 AM
Answer

Kiran Jai

Rank: Junior Member

Posts: 38

Join Date: April 9, 2012

Recent Posts

Thanks Jay .
Jay Patel
RE: Liferay 6.1 : How to associate Listener in my case ??
August 1, 2012 7:56 AM
Answer

Jay Patel

Rank: Regular Member

Posts: 116

Join Date: February 23, 2010

Recent Posts

You're welcome Kiran, but do look the post & feedback given by David as well.

-Jay.
clint barbosa
RE: Liferay 6.1 : How to associate Listener in my case ??
August 23, 2012 3:27 AM
Answer

clint barbosa

Rank: New Member

Posts: 7

Join Date: August 23, 2012

Recent Posts

I've read two of your posts with the same problem, but I still can't find the exactanswer .. And I've searched through the web . Creating model listers for core service is ok,
How to do it to a custom model / table ..

Steps for creating model listener for core models, (BlogsEntry)
- Create your class extending BaseModelListener<BlogsEntry> and implementing all necessary methods (onAfterCreate , onAfterRemove etc.....)
- define in liferay-hook.xml your portal.properties
- in portal.properties put this key and value :
value.object.listener.com.liferay.portlet.blogs.model.BlogsEntry = com.ModelListenerBlogsEntry

This is ok for model listener for BlogsEntry, how to do for custom model.. for my case I want to systemout. everytime i write into ALERT table which is using the Alert model
i found this in the persistence class "value.object.listener.com.alerts.builder.model.Alert" .. so I did the same implementation from blogsEntry in the same portal.properties as well .. I put in this :

value.object.listener.com.alerts.builder.model.Alert = com.alerts.alertutilities.ModelListenerCust ..

but I have the following error :

10:12:58,862 ERROR [HotDeployUtil:114] com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering hook for AlertsAdministration-portlet
com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering hook for AlertsAdministration-portlet
at com.liferay.portal.kernel.deploy.hot.BaseHotDeployListener.throwHotDeployException(BaseHotDeployListener.java:46)
at com.liferay.portal.deploy.hot.HookHotDeployListener.invokeDeploy(HookHotDeployListener.java:307)
at com.liferay.portal.kernel.deploy.hot.HotDeployUtil._doFireDeployEvent(HotDeployUtil.java:111)
at com.liferay.portal.kernel.deploy.hot.HotDeployUtil._fireDeployEvent(HotDeployUtil.java:188)
at com.liferay.portal.kernel.deploy.hot.HotDeployUtil.fireDeployEvent(HotDeployUtil.java:40)
at com.liferay.portal.kernel.servlet.PortletContextListener.doPortalInit(PortletContextListener.java:101)
at com.liferay.portal.kernel.util.BasePortalLifecycle.portalInit(BasePortalLifecycle.java:42)
at com.liferay.portal.kernel.util.PortalLifecycleUtil.register(PortalLifecycleUtil.java:61)
at com.liferay.portal.kernel.util.PortalLifecycleUtil.register(PortalLifecycleUtil.java:53)
at com.liferay.portal.kernel.util.BasePortalLifecycle.registerPortalLifecycle(BasePortalLifecycle.java:52)
at com.liferay.portal.kernel.servlet.PortletContextListener.contextInitialized(PortletContextListener.java:55)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4765)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5260)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:866)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:842)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1095)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1617)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: com.liferay.portal.kernel.bean.BeanLocatorException: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'com.alerts.builder.service.persistence.AlertPersistence' is defined
at com.liferay.portal.bean.BeanLocatorImpl.locate(BeanLocatorImpl.java:70)
at com.liferay.portal.kernel.bean.PortalBeanLocatorUtil.locate(PortalBeanLocatorUtil.java:48)
at com.liferay.portal.deploy.hot.HookHotDeployListener.getPersistence(HookHotDeployListener.java:1169)
at com.liferay.portal.deploy.hot.HookHotDeployListener.initModelListener(HookHotDeployListener.java:1513)
at com.liferay.portal.deploy.hot.HookHotDeployListener.initModelListeners(HookHotDeployListener.java:1544)
at com.liferay.portal.deploy.hot.HookHotDeployListener.doInvokeDeploy(HookHotDeployListener.java:608)
at com.liferay.portal.deploy.hot.HookHotDeployListener.invokeDeploy(HookHotDeployListener.java:304)
... 23 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'com.alerts.builder.service.persistence.AlertPersistence' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:529)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1094)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:276)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1075)
at com.liferay.portal.bean.BeanLocatorImpl.doLocate(BeanLocatorImpl.java:114)
at com.liferay.portal.bean.BeanLocatorImpl.locate(BeanLocatorImpl.java:67)
... 29 more



Am I missing a step ? Thanks in advance for you replies
David H Nebinger
RE: Liferay 6.1 : How to associate Listener in my case ??
August 23, 2012 5:27 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 7238

Join Date: September 1, 2006

Recent Posts

clint barbosa:
Am I missing a step ? Thanks in advance for you replies


You can only hook model listeners for core services.

For your own services, the listeners must be part of the project that is providing the service, as that project is the only project with the necessary beans.
clint barbosa
RE: Liferay 6.1 : How to associate Listener in my case ??
August 23, 2012 7:45 PM
Answer

clint barbosa

Rank: New Member

Posts: 7

Join Date: August 23, 2012

Recent Posts

David H Nebinger:
You can only hook model listeners for core services.

For your own services, the listeners must be part of the project that is providing the service, as that project is the only project with the necessary beans.


I am trying to create a model listener for a custom entity, like the "Alert" .. and I did all these inside 1 project. so all the necessary beans are there
Richard Tichy
RE: Liferay 6.1 : How to associate Listener in my case ??
September 3, 2012 7:50 AM
Answer

Richard Tichy

Rank: New Member

Posts: 4

Join Date: August 16, 2012

Recent Posts

Hello,

I am unfortunately experiencing the same prioblem as Clint.

I am using the Liferay IDE (Eclipse Juno) with Liferay 6.1 and the latest Liferay Plugin SDK.

I first tried creating a hook in my portlet plugin project by adding an entry into portal.properties that looks like like this:

value.object.listener.path.to.my.model.MyModel=path.to,my.listener.MyModelListener

MyModel is the interface generated by ServiceBuilder for my entity, obviously...

I received a very similar error to Clint's when deploying my portlet; No bean called MyModelPersistence is defined.

I then tried adding the same portal.properties entry as described above in a hook plugin project (I copied the generated jar with all the service classes from the portlet plug-in project into the hook project) and received the same error as it was deployed to tomcat.

Could it be that we are running into this bug here?

http://issues.liferay.com/browse/LPS-18831

Not sure what else to do here as this is definitely not working as advertised ;)

Ciao,

Richard
Richard Tichy
RE: Liferay 6.1 : How to associate Listener in my case ??
September 3, 2012 8:15 AM
Answer

Richard Tichy

Rank: New Member

Posts: 4

Join Date: August 16, 2012

Recent Posts

This is definitely a bug...

http://issues.liferay.com/browse/LPS-15144

unfortunately this issue seems to have a pretty low priority...
David H Nebinger
RE: Liferay 6.1 : How to associate Listener in my case ??
September 3, 2012 8:47 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 7238

Join Date: September 1, 2006

Recent Posts

Your model listeners must be in the same plugin project as the persistence classes.

You cannot add a model listener outside of that project.
Richard Tichy
RE: Liferay 6.1 : How to associate Listener in my case ??
September 4, 2012 12:35 AM
Answer

Richard Tichy

Rank: New Member

Posts: 4

Join Date: August 16, 2012

Recent Posts

Actually, that was the first thing I tried (please see my first post). It was only after this failed that I tried creating a separate project just for the custom model listener hook. I added the jar containing the persistence classes needed and that failed as well.

Seems that at this time you can really only create custom listeners for "any model class in Liferay". That being a direct quote from Sezov's "Liferay In Action", for what it is worth. Seems that a custom model listener for a "custom model" created for an entity by Liferay simply does not work at this time, unless I am really missing something.
Richard Tichy
RE: Liferay 6.1 : How to associate Listener in my case ??
September 4, 2012 2:16 AM
Answer

Richard Tichy

Rank: New Member

Posts: 4

Join Date: August 16, 2012

Recent Posts

Just to be a little more specific:

It seems you cannot use a hook to create a custom model listener for a custom model created for you using ServiceBulder in a plugin project due to the bean not found exception discussed above.

If I am wrng about this I would love for someone to tell me what I am doing wrong...
Tanaji Londhe
RE: Liferay 6.1 : How to associate Listener in my case ??
November 4, 2012 11:52 PM
Answer

Tanaji Londhe

Rank: Regular Member

Posts: 196

Join Date: April 25, 2012

Recent Posts

I have create custom listener using hook for AssetEntry
create portal.properties
add entry for listener :- value.object.listener.com.liferay.portlet.asset.model.AssetEntry=org.custom.listeners.CustomAssetEntryListener
But when i open liferay-hook.xml file hook configuration shows following error :
- Invalid portal property name name.
- value.object.listener.com.liferay.portlet.asset.model.AssetEntry" is not among possible values for name.
How to solve this issue?
Rubén Romero Montes
RE: Liferay 6.1 : How to associate Listener in my case ??
November 21, 2012 7:40 AM
Answer

Rubén Romero Montes

Rank: New Member

Posts: 5

Join Date: November 13, 2012

Recent Posts

Richard Tichy:
Just to be a little more specific:

It seems you cannot use a hook to create a custom model listener for a custom model created for you using ServiceBulder in a plugin project due to the bean not found exception discussed above.

If I am wrng about this I would love for someone to tell me what I am doing wrong...


It's been happenning also to me and I've seen that in the deployment, if you're trying to add a listener to your.package.model.Foo, the portal looks up for the FooPersistence bean in the portal's classloader where it doesn't exist.

You can try adding your *-portal-service.jar as a plugin-ext (including the FooPersistence interface) and it won't work because you also need to declare it as a bean in the portal-spring.xml config which is done adding the file ext-spring.xml to your plugin-ext whith the your.package.service.persistence.FooPersistence bean definition pointing to the FooPersistenceImpl which also has to be in the classloader.
Something like this:
1<?xml version="1.0" encoding="UTF-8"?>
2
3<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" default-destroy-method="destroy" default-init-method="afterPropertiesSet" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
4    <bean id="your.package.service.persistence.FooPersistence" class="your.package.service.persistence.FooPersistenceImpl" parent="basePersistence" />
5</beans>   


Then, as I've seen you cannot add listeners to your beans without adding the whole implementation in the portal's classloader. If I'm wrong please correct me.

Regards!
Martin Wiegand
RE: Liferay 6.1 : How to associate Listener in my case ??
August 7, 2014 7:01 AM
Answer

Martin Wiegand

Rank: New Member

Posts: 6

Join Date: March 8, 2011

Recent Posts

Hey Guys,

we found a workaround to register model listeners on other custom plugin entites in a Portlet/Hook Plugin (testet with Liferay 6.2):

The Steps are:

1. Add a Hook StartupAction
2. Register your ModelListener programmatically in this action like in the following in code snippet

This is an example to register a CalendarBooking (which is a portlet plugin entity) ModelListener:
 1
 2// lookup the BasePersistence of the target plugin entity
 3// use the ClpSerializer instance of the target plugin entity service
 4BasePersistence calendarBookingPersistence = (BasePersistence) PortletBeanLocatorUtil.locate(ClpSerializer.getServletContextName(),
 5                "com.liferay.calendar.service.persistence.CalendarBookingPersistence");
 6      
 7ModelListener[] listeners = calendarBookingPersistence.getListeners();
 8// remove all old instances of our listener to avoid multiple registrations on hot deployment
 9for (ModelListener modelListener : listeners) {
10    if (modelListener.getClass().getName().equals(CalendarBookingListener.class.getName())){
11        calendarBookingPersistence.unregisterListener(modelListener);
12    }
13}
14
15calendarBookingPersistence.registerListener(new MyCalendarBookingListener());


There's only one restriction because of class loading restrictions: MyCalendarBookingListener must be of generic type BaseModel (MyCalendarBookingListener<BaseModel>).
1public void onBeforeCreate(BaseModel model)

Then you can get the primary key like that:
1long myEntityPK =  GetterUtil.getLong(model.getPrimaryKeyObj())


Regards,
Martin

PRODYNA AG
David H Nebinger
RE: Liferay 6.1 : How to associate Listener in my case ??
August 7, 2014 6:48 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 7238

Join Date: September 1, 2006

Recent Posts

Rubén Romero Montes:
Then, as I've seen you cannot add listeners to your beans without adding the whole implementation in the portal's classloader. If I'm wrong please correct me.


Yes, you guys are all wrong.

The only place you can define listeners on your own model classes is in the plugin that implements the service. It cannot be a separate hook, it cannot be in some other plugin using the service jar, ...

The only place is in the implementation.

Liferay model listeners can be added as hooks because the runtime context for the hook is the portal's context, and therefore those model listeners are also in the plugin that implements the service (the portal).
David H Nebinger
RE: Liferay 6.1 : How to associate Listener in my case ??
August 7, 2014 7:03 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 7238

Join Date: September 1, 2006

Recent Posts

Martin Wiegand:
we found a workaround to register model listeners on custom entites (testet with Liferay 6.2):

The Steps are:

1. Add a Hook StartupAction
2. Register your ModelListener programmatically in this action like in the following in code snippet

This is an example to register a CalendarBooking (which is a portlet plugin entity) ModelListener


Okay, no one said that you were trying to get to the external canned plugins such as calendar.

The approved way to do this would be to follow the https://www.liferay.com/documentation/liferay-portal/6.2/development/-/ai/creating-plugins-to-extend-plugins-liferay-portal-6-2-dev-guide-03-en path.

This way you start with the plugin that you're extending (i.e. the calendar plugin), but you can add your own code (i.e. the model listeners), but everything is still within the correct runtime context.
Martin Wiegand
RE: Liferay 6.1 : How to associate Listener in my case ??
August 7, 2014 7:15 AM
Answer

Martin Wiegand

Rank: New Member

Posts: 6

Join Date: March 8, 2011

Recent Posts

Okay, our goal was only to use the (calendar) service and to register a model listener out of our own custom portlet. Extending the portlet was not our scope.

By the way: CalendarBooking was just an example for a "portlet plugin entity".
David H Nebinger
RE: Liferay 6.1 : How to associate Listener in my case ??
August 7, 2014 8:23 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 7238

Join Date: September 1, 2006

Recent Posts

Martin Wiegand:
Okay, our goal was only to use the (calendar) service and to register a model listener out of our own custom portlet. Extending the portlet was not our scope.

By the way: CalendarBooking was just an example for a "portlet plugin entity".


The link talks about extending the plugins in other ways such as replacing classes, etc. You're not really going that far, but adding a model listener to a plugin is still an extension.

I can't pick apart your implementation, though, as I'm sure you had other constraints that I'm not privy to.

But for future folks who need to do this, the "plugin extending a plugin" mechanism will be a lot easier than trying to muck around with class loaders and reflection, etc.

Just extend the other plugin, add in your liferay-hook.xml to use the portal properties file, add the properties file to define your model listener classes, and add the code for your listeners.

The upside of this mechanism is that regardless of future changes/upgrades, you won't be impacted.
Debopam Mitra
RE: Liferay 6.1 : How to associate Listener in my case ??
September 3, 2014 5:20 AM
Answer

Debopam Mitra

Rank: Junior Member

Posts: 30

Join Date: September 27, 2012

Recent Posts

Hi David,

What you mean by adding the model listener to the service implementation? Did you mean,

1public class FooModelLocalServiceImpl extends FooModelLocalServiceBaseImpl implements ModelListener<FooModel>{
2
3......
4
5}



Is this what you meant? I did but the same error is being thrown, i.e.,

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'com.edu.service.service.persistence.FooModelPersistence' is defined.

Can you please help?
David H Nebinger
RE: Liferay 6.1 : How to associate Listener in my case ??
September 3, 2014 6:55 PM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 7238

Join Date: September 1, 2006

Recent Posts

No, it would be like any other listener implementation. You have a class which implements the ModelListener interface and register the class in the properties file. That will allow you to add a listener to a canned plugin, something you cannot do using a hook.
Debopam Mitra
RE: Liferay 6.1 : How to associate Listener in my case ??
September 3, 2014 10:44 PM
Answer

Debopam Mitra

Rank: Junior Member

Posts: 30

Join Date: September 27, 2012

Recent Posts

You mean it have to be a Portlet Plugin project not a Hook Plugin project?

What you are saying I did 5 - 10 times...

What I am doing is as follows (as per my project requirement):

  1. A hook plugin that hooks the JournalFolder.
  2. On every folder creation I have allowed the user to add thumbnail, and other extra data fields.
  3. I have create a Foo model that saves the above extra fields in the DB.
  4. Now I want a model listener here to listen to the changes and update some other table in my db.


I tried the approach you suggested and all the time I get error on deployment.

Please provide any blog or link that will help me get through this problem.
Debopam Mitra
RE: Liferay 6.1 : How to associate Listener in my case ??
September 4, 2014 2:52 AM
Answer

Debopam Mitra

Rank: Junior Member

Posts: 30

Join Date: September 27, 2012

Recent Posts

FINALLY, mission accomplished.

I declared the listener to my model like:

value.object.listener.com.foo.service.model.Foo=com.foo.hook.impl.FooModelListener

in my service.properties.
David H Nebinger
RE: Liferay 6.1 : How to associate Listener in my case ??
September 4, 2014 9:18 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 7238

Join Date: September 1, 2006

Recent Posts

I think this whole thread has been polluted, so let's try and straighten it out w/ a few concepts...

1. If you want to add a model listener to a core Liferay entity, you can do this simply with a hook.

2. If you want to add a model listener to your own entities, you need to do this as a hook within the plugin offering the service (you cannot hook a model listener in another war file).

3. If you want to add a model listener to a separate war, i.e. the calendar services, you must follow the Liferay instructions for "plugin extending a plugin". Using this method, you can add a hook to the current plugin that has the model listener. So calendar, as the example, you normally cannot have a model listener for, but by extending the calendar plugin you can add a hook to it so you do the model listener.
Debopam Mitra
RE: Liferay 6.1 : How to associate Listener in my case ??
September 7, 2014 11:38 PM
Answer

Debopam Mitra

Rank: Junior Member

Posts: 30

Join Date: September 27, 2012

Recent Posts

Yes, I wasn't hooking my custom entities in a separate plugin project. Let me point out what I did:

  1. I hooked into the JournalFolder to add my features.
  2. Later I wanted to added a custom entity that need to save the extra fields I have put in the JournalFolder custom jsp hook.
  3. Then I needed to listen to this custom entity's CRUD operations. So thought of implementing the Model Listeners.
  4. Please note that till here I have, custom jsp hook, service hook, service builder and the model listener all in the same project. And as per the given documentation and wiki I tried to do as directed.


But finally had to resort to the above process, i.e. registering the ModelListener in my service.properties.

Is it wrong for the given scenario?