Foros de discusión
Liferay 5.2 Model Listeners (Hooks)
Peter Mesotten, modificado hace 15 años.
Liferay 5.2 Model Listeners (Hooks)
Junior Member Mensajes: 45 Fecha de incorporación: 4/02/09 Mensajes recientes
I'm trying to define a Model Listener hook using the 5.2 definition for hooks. In 5.1 you could specify your model listeners in liferay-hook.xml:
Since 5.2 you have to do it in the portal.properties. So I define my hook like this:
I put a custom portal-ext.properties inside my src folder and enter:
In my listener, I perform an action on creation of an ExpandoValue:
But on form submit, nothing gets logged... What's going wrong? In 5.1 this worked perfectly.
<hook>
<model-listener>
<model-listener-class>be.aca.RegistrationValueListener</model-listener-class>
<model-name>com.liferay.portlet.expando.model.ExpandoValue</model-name>
</model-listener>
</hook>
Since 5.2 you have to do it in the portal.properties. So I define my hook like this:
<!--?xml version="1.0" encoding="UTF-8"?-->
<hook>
<portal-properties>portal-ext.properties</portal-properties>
</hook>
I put a custom portal-ext.properties inside my src folder and enter:
value.object.listener.com.liferay.portlet.expando.model.ExpandoValue=be.aca.RegistrationValueListener
In my listener, I perform an action on creation of an ExpandoValue:
public class RegistrationValueListener implements ModelListener {
//...
@Override
public void onAfterCreate(BaseModel model) throws ModelListenerException {
System.out.println("BLABLA");
}
//...
}
But on form submit, nothing gets logged... What's going wrong? In 5.1 this worked perfectly.
Atma -, modificado hace 14 años.
RE: Liferay 5.2 Model Listeners (Hooks)
Junior Member Mensajes: 99 Fecha de incorporación: 7/04/06 Mensajes recientes
I have exactly the same problem !
With a "UserModelListener" it works perfectly, but with expando, nothing happens :-(
With a "UserModelListener" it works perfectly, but with expando, nothing happens :-(
Simon Göransson, modificado hace 13 años.
RE: Liferay 5.2 Model Listeners (Hooks)
New Member Mensajes: 5 Fecha de incorporación: 25/10/10 Mensajes recientes
I also have the same problem in liferay 6.05
works fine with a listener for user, but not for any expando field.
Does anyone know why it does not work?
//Simon
works fine with a listener for user, but not for any expando field.
Does anyone know why it does not work?
//Simon
Charles de Courval, modificado hace 12 años.
RE: Liferay 5.2 Model Listeners (Hooks)
Junior Member Mensajes: 55 Fecha de incorporación: 31/07/10 Mensajes recientes
Did anyone find a solution to this problem ?
Chris Chan, modificado hace 12 años.
RE: Liferay 5.2 Model Listeners (Hooks)
Junior Member Mensajes: 39 Fecha de incorporación: 23/07/10 Mensajes recientes
I'm also looking for a similar solution.
I was told to use a wrapper plugin (http://www.liferay.com/community/wiki/-/wiki/Main/Wrapper+Plugins) but I'm assuming the ExpandoValueLocalServiceWrapper is the correct one to extend, in particular the updateExpandoValue method?
If this is correct, then is there a set mapping of class names to classNameId so that I could then do a reverse lookup based on the classPK?
I was told to use a wrapper plugin (http://www.liferay.com/community/wiki/-/wiki/Main/Wrapper+Plugins) but I'm assuming the ExpandoValueLocalServiceWrapper is the correct one to extend, in particular the updateExpandoValue method?
If this is correct, then is there a set mapping of class names to classNameId so that I could then do a reverse lookup based on the classPK?
Chris Chan, modificado hace 12 años.
RE: Liferay 5.2 Model Listeners (Hooks)
Junior Member Mensajes: 39 Fecha de incorporación: 23/07/10 Mensajes recientes
So I got this working in my solution using something similar to what Peter wrote above, however in my case, I was trying to create a listener in the Audit Hook.
First, Liferay support has mentioned that the User listener not firing for expando value changes is the expected behavior and we have no choice but to look at the expando itself.
So to do this, I created a listener against the ExpandoValue model. As Peter mentioned above, I added a line in the portal-ext.properties like so:
For my situation, I was checking for updates only to an existing expando field on the User. So my class looks something like this:
Hope this helps,
Chris
First, Liferay support has mentioned that the User listener not firing for expando value changes is the expected behavior and we have no choice but to look at the expando itself.
So to do this, I created a listener against the ExpandoValue model. As Peter mentioned above, I added a line in the portal-ext.properties like so:
value.object.listener.com.liferay.portlet.expando.model.ExpandoValue=com.liferay.portal.audit.hook.listeners.ExpandoValueListener
For my situation, I was checking for updates only to an existing expando field on the User. So my class looks something like this:
public class ExpandoValueListener extends BaseModelListener<expandovalue> {
public void onBeforeUpdate(ExpandoValue expandoValue) throws ModelListenerException {
//Check if the expando value being updated is a user attribute
Long classNameId = ClassNameLocalServiceUtil.getClassNameId("com.liferay.portal.model.User");
if(expandoValue.getClassNameId() == classNameId){
.........
}
}
}
</expandovalue>
Hope this helps,
Chris
Charles de Courval, modificado hace 12 años.
RE: Liferay 5.2 Model Listeners (Hooks)
Junior Member Mensajes: 55 Fecha de incorporación: 31/07/10 Mensajes recientes
Hi,
I finally found a solution to my listener problems. I've described it here.
It's all related to a bug in Liferay LPS-10988 .
cheers.
I finally found a solution to my listener problems. I've described it here.
It's all related to a bug in Liferay LPS-10988 .
cheers.