Forums

Home » Liferay Portal » English » 3. Development »

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Liferay Support ACA
Liferay 5.2 Model Listeners (Hooks)
April 8, 2009 6:04 AM
Answer

Liferay Support ACA

Rank: Junior Member

Posts: 32

Join Date: February 4, 2009

Recent Posts

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:

<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"?>
<!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 5.2.0//EN" "http://www.liferay.com/dtd/liferay-hook_5_2_0.dtd">
<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 -
RE: Liferay 5.2 Model Listeners (Hooks)
November 24, 2009 8:51 AM
Answer

Atma -

Rank: Junior Member

Posts: 99

Join Date: April 6, 2006

Recent Posts

I have exactly the same problem !

With a "UserModelListener" it works perfectly, but with expando, nothing happens :-(
Simon Göransson
RE: Liferay 5.2 Model Listeners (Hooks)
February 10, 2011 6:03 AM
Answer

Simon Göransson

Rank: New Member

Posts: 2

Join Date: October 25, 2010

Recent Posts

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
Charles de Courval
RE: Liferay 5.2 Model Listeners (Hooks)
May 15, 2011 7:29 AM
Answer

Charles de Courval

Rank: Junior Member

Posts: 55

Join Date: July 31, 2010

Recent Posts

Did anyone find a solution to this problem ?
Chris Chan
RE: Liferay 5.2 Model Listeners (Hooks)
May 31, 2011 6:48 PM
Answer

Chris Chan

Rank: Junior Member

Posts: 38

Join Date: July 23, 2010

Recent Posts

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?
Chris Chan
RE: Liferay 5.2 Model Listeners (Hooks)
May 31, 2011 10:02 PM
Answer

Chris Chan

Rank: Junior Member

Posts: 38

Join Date: July 23, 2010

Recent Posts

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:
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){
                                    .........
            }
    }
}


Hope this helps,
Chris
Charles de Courval
RE: Liferay 5.2 Model Listeners (Hooks)
June 3, 2011 7:17 AM
Answer

Charles de Courval

Rank: Junior Member

Posts: 55

Join Date: July 31, 2010

Recent Posts

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.