Message Boards

How to Create Model Listener Class in Plugin?

thumbnail
Faisal K, modified 14 Years ago.

How to Create Model Listener Class in Plugin?

Regular Member Posts: 138 Join Date: 1/9/08 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.
thumbnail
Wilson Man, modified 14 Years ago.

RE: How to Create Model Listener Class in Plugin?

Liferay Master Posts: 581 Join Date: 6/21/06 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 ...
thumbnail
Faisal K, modified 14 Years ago.

RE: How to Create Model Listener Class in Plugin?

Regular Member Posts: 138 Join Date: 1/9/08 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?
thumbnail
Wilson Man, modified 14 Years ago.

RE: How to Create Model Listener Class in Plugin?

Liferay Master Posts: 581 Join Date: 6/21/06 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:
value.object.listener.com.<the_rest_of_your_class_path></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.
thumbnail
Faisal K, modified 14 Years ago.

RE: How to Create Model Listener Class in Plugin?

Regular Member Posts: 138 Join Date: 1/9/08 Recent Posts
Hi,

Thanks for your Reply, I will try this.
thumbnail
Stef Heyenrath, modified 14 Years ago.

RE: How to Create Model Listener Class in Plugin?

Junior Member Posts: 76 Join Date: 12/3/08 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:
<target name="build-service" depends="clean">
	<ant antfile="../build-common-portlet.xml" target="build-service" />

	<concat destfile="${src}/service.properties" append="true" fixlastline="yes" eol="crlf">
		<filelist dir="${src}" files="service-ext.properties" />
	</concat>
</target>


Because I use concat, I need some more CRLF's at the top of the service-ext.properties :



# Do not remove CRLFs at the top of this file !!!

# Listeners
value.object.listener.com.test.model.MyEntity=com.test.services.listeners.MyEntity


I hope this helps.
thumbnail
charles de courval, modified 13 Years ago.

RE: How to Create Model Listener Class in Plugin?

Junior Member Posts: 55 Join Date: 7/31/10 Recent Posts
Hi Wilson,
I tried your solution, and I have the following problem:
Loading file:/C:/projects/ACQ/trunk/programs/liferay-portal-6.0.5/tomcat-6.0.26/webapps/ACQ-portlet/WEB-INF/classes/service.properties
16:15:19,090 ERROR [EnterprisePersistenceImpl:2452] 
java.lang.ClassNotFoundException: com.acq.portlet.enterprise.model.impl.EnterpriseListener
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1516)
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1361)
.......


The configuration in service.properties is as follows:
value.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 ?
thumbnail
Paul ., modified 12 Years ago.

RE: How to Create Model Listener Class in Plugin?

Liferay Master Posts: 522 Join Date: 8/29/11 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?
thumbnail
Paul ., modified 12 Years ago.

RE: How to Create Model Listener Class in Plugin?

Liferay Master Posts: 522 Join Date: 8/29/11 Recent Posts
After some searching , there is a workaround on http://issues.liferay.com/browse/LPS-10988
thumbnail
Ivano Carrara, modified 12 Years ago.

RE: How to Create Model Listener Class in Plugin?

Expert Posts: 345 Join Date: 7/3/05 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:

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


... 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.
thumbnail
Ivano Carrara, modified 12 Years ago.

RE: How to Create Model Listener Class in Plugin?

Expert Posts: 345 Join Date: 7/3/05 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:

value.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.
thumbnail
Ivano Carrara, modified 12 Years ago.

RE: How to Create Model Listener Class in Plugin?

Expert Posts: 345 Join Date: 7/3/05 Recent Posts
Hi Charles, maibe you solved the java.lang.ClassNotFoundException error ?

Thank you for some help...

Ivano C.
Kirk Stork, modified 11 Years ago.

RE: How to Create Model Listener Class in Plugin?

Junior Member Posts: 33 Join Date: 5/19/10 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:
value.object.listener.com.<the_rest_of_your_class_path></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?
ronak vora, modified 3 Years ago.

RE: How to Create Model Listener Class in Plugin?

Junior Member Posts: 25 Join Date: 9/26/18 Recent Posts
Hello Wilson Man,
       There is into service.properties file entry deleted automatically can we have any solution.
and i've make entry into hook > portal.properties 
value.object.listener.org.food.model.FoodModel=com.food.listeners.Foodistener

does anything else require to add CustomModelListener(FoodModelListener)?