Foren

Home » Liferay Portal » English » 3. Development

Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
Tanaji Londhe
modelListener overridden method get previous data.
22. Oktober 2012 00:24
Antwort

Tanaji Londhe

Rang: Regular Member

Nachrichten: 196

Eintrittsdatum: 25. April 2012

Neue Beiträge

Hi,
Here I extend myclass using BaseModelListener class override some method like.
@Override
public void onAfterUpdate(User model) throws ModelListenerException {.........}
In this method i try to access Organization which related the User using --------> list = model.getOrganizations();
But here always I am getting previous value of a organization.
How sholud i get selected organization in a listener.
Tanaji Londhe
RE: modelListener overridden method get previous data.
22. Oktober 2012 02:18
Antwort

Tanaji Londhe

Rang: Regular Member

Nachrichten: 196

Eintrittsdatum: 25. April 2012

Neue Beiträge

Can anybody help me, its urgent requirement plz.
Tanaji Londhe
RE: modelListener overridden method get previous data.
27. Oktober 2012 00:20
Antwort

Tanaji Londhe

Rang: Regular Member

Nachrichten: 196

Eintrittsdatum: 25. April 2012

Neue Beiträge

Hi,
I update my server from 6.1.0 to 6.1.1
I have similar with Organization listener for custom field in onAfterUpdate() mtd. But in new version of a liferay 6.1.1 the issue is resolve.
Now i get updated value for custom field in onAfterUpdate() mtd. emoticon

But for UserListener issue is not solve till now. list = model.getOrganizations(); Still I am gettting old value for organization.
David H Nebinger
RE: modelListener overridden method get previous data.
27. Oktober 2012 13:22
Antwort

David H Nebinger

Rang: Liferay Legend

Nachrichten: 7250

Eintrittsdatum: 1. September 2006

Neue Beiträge

you do not need to override listeners, all listeners for a particular model will get invoked.
Tanaji Londhe
RE: modelListener overridden method get previous data.
29. Oktober 2012 01:26
Antwort

Tanaji Londhe

Rang: Regular Member

Nachrichten: 196

Eintrittsdatum: 25. April 2012

Neue Beiträge

Hi David,
Thanks for your reply.
You are saying is complete right, but here my requirement is to add some other functionality which is related to non-liferay DB. (like performing CRUD operation on non-liferay DB.)
So thats why I override User and Organization listeners in my code using hook.
But my problem is updating user's Organization through control panel.
I am not getting updated value of select org for particular user in my overriden listener ---
@Override
public void onAfterUpdate(User model) throws ModelListenerException {
System.out.println("onAfterUpdate()"+model.getUserId());
try {
List<Organization> orgList = model.getOrganizations();
for (Iterator iterator = orgList.iterator(); iterator.hasNext();) {
Organization organization = (Organization) iterator.next();
System.out.println("User Organization : "+organization.getName());
// here i am getting old(previous) value of a Organization, when i update any user.
}
} catch (PortalException e) {
e.printStackTrace();
} catch (SystemException e) {
e.printStackTrace();
}
super.onAfterUpdate(model);
}
Nikhil Nishchal
RE: modelListener overridden method get previous data.
29. Oktober 2012 02:01
Antwort

Nikhil Nishchal

Rang: Junior Member

Nachrichten: 82

Eintrittsdatum: 21. Juni 2012

Neue Beiträge

On model change try to reindex organization manually and then check.
Hope if re-indexing issue then this may be solve.

Indexer indexer = IndexerRegistryUtil.getIndexer(Organization.class);

indexer.reindex(organization);

and then again get organization by organizationId.
Gaurav Jain
RE: modelListener overridden method get previous data.
29. Oktober 2012 02:11
Antwort

Gaurav Jain

Rang: Regular Member

Nachrichten: 141

Eintrittsdatum: 31. Januar 2011

Neue Beiträge

Once I had similar problems, but don't remember exactly either it was for User or for CalEvent model.

But on checking the source, I found that modelListeners are being invoked by persistenceImpl class methods. For taking User instance: updateUser method of userLocalServiceImpl calls userPersistance update method which further invokes model listeners on this model. And in userLocalServiceImpl updateUser method it further performs more operations like expando, contact etc after the persistance update has been done.

In my case, I remember that I solved my problem by calling model listener of assetEntry and checking user /calEvent instance there instead of calling user model listener.

But I might not be completely right !!
Tanaji Londhe
RE: modelListener overridden method get previous data.
29. Oktober 2012 02:44
Antwort

Tanaji Londhe

Rang: Regular Member

Nachrichten: 196

Eintrittsdatum: 25. April 2012

Neue Beiträge

I perform re-indexing in my code but its not working.
Tanaji Londhe
RE: modelListener overridden method get previous data.
29. Oktober 2012 05:41
Antwort

Tanaji Londhe

Rang: Regular Member

Nachrichten: 196

Eintrittsdatum: 25. April 2012

Neue Beiträge

In my case, I remember that I solved my problem by calling model listener of assetEntry and checking user /calEvent instance there instead of calling user model listener.

Hi Gaurav,
I am not getting this part, can you elaborate this thing.
Gaurav Jain
RE: modelListener overridden method get previous data.
29. Oktober 2012 06:34
Antwort

Gaurav Jain

Rang: Regular Member

Nachrichten: 141

Eintrittsdatum: 31. Januar 2011

Neue Beiträge

Tanaji M. Londhe:


Hi Gaurav,
I am not getting this part, can you elaborate this thing.


You may try following:
Instead of applying model listener on Organization; apply on AssetEntry. And then onAfterUpdate of it, you can detect if that assetEntry is of type Organization, then execute your code.
Tanaji Londhe
RE: modelListener overridden method get previous data.
31. Oktober 2012 03:50
Antwort

Tanaji Londhe

Rang: Regular Member

Nachrichten: 196

Eintrittsdatum: 25. April 2012

Neue Beiträge

can you explain me how to get Organization type from assetEntry?
Gaurav Jain
RE: modelListener overridden method get previous data.
31. Oktober 2012 04:14
Antwort

Gaurav Jain

Rang: Regular Member

Nachrichten: 141

Eintrittsdatum: 31. Januar 2011

Neue Beiträge

 1public class CustomAssetEntryListener extends BaseModelListener<AssetEntry>{
 2        @Override
 3        public void onAfterUpdate(AssetEntry assetEntry)
 4                throws ModelListenerException {
 5
 6                long orgClassNameId=ClassNameLocalServiceUtil.getClassNameId(Organization.class);
 7                if(assetEntry.getClassNameId()==orgClassNameId){
 8                     // Your code goes here
 9                }
10
11                super.onAfterUpdate(assetEntry);
12        }
Tanaji Londhe
RE: modelListener overridden method get previous data.
31. Oktober 2012 06:03
Antwort

Tanaji Londhe

Rang: Regular Member

Nachrichten: 196

Eintrittsdatum: 25. April 2012

Neue Beiträge

Thanks Gaurav, Its working fine. emoticon