Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Tanaji Londhe
modelListener overridden method get previous data.
October 22, 2012 12:24 AM
Answer

Tanaji Londhe

Rank: Regular Member

Posts: 197

Join Date: April 25, 2012

Recent Posts

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.
October 22, 2012 2:18 AM
Answer

Tanaji Londhe

Rank: Regular Member

Posts: 197

Join Date: April 25, 2012

Recent Posts

Can anybody help me, its urgent requirement plz.
Tanaji Londhe
RE: modelListener overridden method get previous data.
October 27, 2012 12:20 AM
Answer

Tanaji Londhe

Rank: Regular Member

Posts: 197

Join Date: April 25, 2012

Recent Posts

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.
October 27, 2012 1:22 PM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 6701

Join Date: September 1, 2006

Recent Posts

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.
October 29, 2012 1:26 AM
Answer

Tanaji Londhe

Rank: Regular Member

Posts: 197

Join Date: April 25, 2012

Recent Posts

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.
October 29, 2012 2:01 AM
Answer

Nikhil Nishchal

Rank: Junior Member

Posts: 74

Join Date: June 21, 2012

Recent Posts

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.
October 29, 2012 2:11 AM
Answer

Gaurav Jain

Rank: Regular Member

Posts: 141

Join Date: January 31, 2011

Recent Posts

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.
October 29, 2012 2:44 AM
Answer

Tanaji Londhe

Rank: Regular Member

Posts: 197

Join Date: April 25, 2012

Recent Posts

I perform re-indexing in my code but its not working.
Tanaji Londhe
RE: modelListener overridden method get previous data.
October 29, 2012 5:41 AM
Answer

Tanaji Londhe

Rank: Regular Member

Posts: 197

Join Date: April 25, 2012

Recent Posts

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.
October 29, 2012 6:34 AM
Answer

Gaurav Jain

Rank: Regular Member

Posts: 141

Join Date: January 31, 2011

Recent Posts

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.
October 31, 2012 3:50 AM
Answer

Tanaji Londhe

Rank: Regular Member

Posts: 197

Join Date: April 25, 2012

Recent Posts

can you explain me how to get Organization type from assetEntry?
Gaurav Jain
RE: modelListener overridden method get previous data.
October 31, 2012 4:14 AM
Answer

Gaurav Jain

Rank: Regular Member

Posts: 141

Join Date: January 31, 2011

Recent Posts

 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.
October 31, 2012 6:03 AM
Answer

Tanaji Londhe

Rank: Regular Member

Posts: 197

Join Date: April 25, 2012

Recent Posts

Thanks Gaurav, Its working fine. emoticon