Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Faisal K
How to Create Model Listener Class in Plugin?
June 2, 2009 2:48 AM
Answer

Faisal K

Rank: Regular Member

Posts: 138

Join Date: January 9, 2008

Recent Posts

Hi All,


I want to create a Model listener class for one of my service entities created under plugin environement,If any body have done this before, please help me how to do this?

One more thing I am seeing there are some extra classes like 'CLPMessageListener' is created only for plugin environement, what are these classes all about?

Thanks In advance.
Wilson Man
RE: How to Create Model Listener Class in Plugin?
June 3, 2009 7:13 PM
Answer

Wilson Man

LIFERAY STAFF

Rank: Liferay Master

Posts: 580

Join Date: June 21, 2006

Recent Posts

http://www.liferay.com/web/guest/community/forums/-/message_boards/message/2648040

as for the CLP stuff, i believe those are for hot deployment ...
Faisal K
RE: How to Create Model Listener Class in Plugin?
June 4, 2009 10:28 PM
Answer

Faisal K

Rank: Regular Member

Posts: 138

Join Date: January 9, 2008

Recent Posts

Thanks for the reply Wilson,

Actually I want to write a Listener class for one of my Service Entity, means when I am creating or updating that entity I want to do some action like sending a mail, etc. I think it can be doable using ModelListener but I have to mention it in

value.object.listener.${model.class.} in portal-ext.properties this is for EXT environment (User,Message Board listeners are working fine), now I am trying to do the same in plugin environment using portlet.properties, but not working, is there any other way like hook. Earlier in the Hook there was a tag to mention the Events(model-listener exists in 5.0 dtd) but not exists in 5.2.0 dtd., Can you help me what is the other solution for doing this?
Wilson Man
RE: How to Create Model Listener Class in Plugin?
June 5, 2009 12:48 PM
Answer

Wilson Man

LIFERAY STAFF

Rank: Liferay Master

Posts: 580

Join Date: June 21, 2006

Recent Posts

oh right, i misread your post. Yeah, what you want to do is this ...

1. in your entity's PersistenceImpl class, do a search for the string "value.object". You'll find something like this:
1value.object.listener.com.<the_rest_of_your_class_path>

2. copy and paste that into docroot/WEB-INF/src/service.properties and set that = to your custom model listener
3. (i guess this should be step 1 really) create your custom listener and extend the BaseModelListener class


One thing to note though, due to some constraints in easyconf, service-ext.properties doesn't work as it should. So you need to put this property in your service.properties file. And re-add it back each time you rebuild your services cuz ant build-service will remove your entries.
Faisal K
RE: How to Create Model Listener Class in Plugin?
June 7, 2009 9:24 PM
Answer

Faisal K

Rank: Regular Member

Posts: 138

Join Date: January 9, 2008

Recent Posts

Hi,

Thanks for your Reply, I will try this.
Stef Heyenrath
RE: How to Create Model Listener Class in Plugin?
June 26, 2009 7:08 AM
Answer

Stef Heyenrath

Rank: Junior Member

Posts: 76

Join Date: December 3, 2008

Recent Posts

Wilson Man:

One thing to note though, due to some constraints in easyconf, service-ext.properties doesn't work as it should. So you need to put this property in your service.properties file. And re-add it back each time you rebuild your services cuz ant build-service will remove your entries.


I fixed this by overriding the build-service target in the build.xml from the portlet:
1<target name="build-service" depends="clean">
2    <ant antfile="../build-common-portlet.xml" target="build-service"/>
3
4    <concat destfile="${src}/service.properties" append="true" fixlastline="yes" eol="crlf">
5        <filelist dir="${src}" files="service-ext.properties" />
6    </concat>
7</target>


Because I use concat, I need some more CRLF's at the top of the service-ext.properties :
1
2
3
4# Do not remove CRLFs at the top of this file !!!
5
6# Listeners
7value.object.listener.com.test.model.MyEntity=com.test.services.listeners.MyEntity


I hope this helps.
Charles de Courval
RE: How to Create Model Listener Class in Plugin?
December 23, 2010 8:27 AM
Answer

Charles de Courval

Rank: Junior Member

Posts: 55

Join Date: July 31, 2010

Recent Posts

Hi Wilson,
I tried your solution, and I have the following problem:
1Loading file:/C:/projects/ACQ/trunk/programs/liferay-portal-6.0.5/tomcat-6.0.26/webapps/ACQ-portlet/WEB-INF/classes/service.properties
216:15:19,090 ERROR [EnterprisePersistenceImpl:2452]
3java.lang.ClassNotFoundException: com.acq.portlet.enterprise.model.impl.EnterpriseListener
4    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1516)
5    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1361)
6.......


The configuration in service.properties is as follows:
1value.object.listener.com.acq.portlet.enterprise.model.Enterprise = com.acq.portlet.enterprise.model.impl.EnterpriseListener

but for some reason the class is never found by the class loader.

The class does exists in my package emoticon

Any idea ?
Bart Simpson
RE: How to Create Model Listener Class in Plugin?
October 17, 2011 5:45 AM
Answer

Bart Simpson

Rank: Liferay Master

Posts: 524

Join Date: August 29, 2011

Recent Posts

but for some reason the class is never found by the class loader.

Having the same problem , has anyone found a solution yet?
Bart Simpson
RE: How to Create Model Listener Class in Plugin?
October 17, 2011 6:17 AM
Answer

Bart Simpson

Rank: Liferay Master

Posts: 524

Join Date: August 29, 2011

Recent Posts

After some searching , there is a workaround on http://issues.liferay.com/browse/LPS-10988
Ivano Carrara
RE: How to Create Model Listener Class in Plugin?
December 10, 2011 4:10 AM
Answer

Ivano Carrara

Rank: Expert

Posts: 305

Join Date: July 2, 2005

Recent Posts

Hi all,

I installed it in Liferay SDK the new buil-common-plugin.xml from the LPS-10988 workaround, then I replaced the name of my service package as below:

1<replace dir="${basedir}/docroot/WEB-INF/src/o2/base/service/persistence" includes="*PersistenceImpl.java" summary="yes">


... and rebuilt the services but the error is still the same:

Caused by: com.liferay.portal.kernel.bean.BeanLocatorException: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'o2.base.service.persistence.OMUserDittaPersistence' is defined


Anyone used the modified build-common-plugin.xml as the workaround from http://issues.liferay.com/browse/LPS-10988 ?

Thank you in advance!

Ivano C.
Ivano Carrara
RE: How to Create Model Listener Class in Plugin?
December 10, 2011 8:48 AM
Answer

Ivano Carrara

Rank: Expert

Posts: 305

Join Date: July 2, 2005

Recent Posts

After reading the entire post and installed in Liferay SDK the new buil-common-plugin.xml from the LPS-10988 workaround, I wrote in the service.properties file the below property:

1value.object.listener.o2.base.model.OMUserDitta=o2.base.listener.UserDittaListener


but during the Tomcat start up still I get the below error:

Loading file:/C:/dev/liferay/bundles/liferay-portal-tomcat-6.0.6/tomcat-6.0.29/webapps/o2-base-portlet/WEB-INF/classes/service.properties
17:40:01,300 ERROR [OMUserDittaPersistenceImpl:6986]
java.lang.ClassNotFoundException: o2.base.listener.UserDittaListener


The names and paths are ok but it can't find my model listener class....

Please, someone can help me?

Thank you!
Ivano C.
Ivano Carrara
RE: How to Create Model Listener Class in Plugin?
December 10, 2011 8:51 AM
Answer

Ivano Carrara

Rank: Expert

Posts: 305

Join Date: July 2, 2005

Recent Posts

Hi Charles, maibe you solved the java.lang.ClassNotFoundException error ?

Thank you for some help...

Ivano C.
Kirk Stork
RE: How to Create Model Listener Class in Plugin?
July 4, 2012 10:01 AM
Answer

Kirk Stork

Rank: Junior Member

Posts: 29

Join Date: May 19, 2010

Recent Posts

Wilson Man:
oh right, i misread your post. Yeah, what you want to do is this ...

1. in your entity's PersistenceImpl class, do a search for the string "value.object". You'll find something like this:
1value.object.listener.com.<the_rest_of_your_class_path>

2. copy and paste that into docroot/WEB-INF/src/service.properties and set that = to your custom model listener
3. (i guess this should be step 1 really) create your custom listener and extend the BaseModelListener class


One thing to note though, due to some constraints in easyconf, service-ext.properties doesn't work as it should. So you need to put this property in your service.properties file. And re-add it back each time you rebuild your services cuz ant build-service will remove your entries.



Isn't there a safe place/way to simply call registerListener() from your plugin's code?