PDA

View Full Version : [GXT 2.0.1]: BeanModelMarker and equals() method from entity



stogi
6 Aug 2009, 10:57 PM
Hi!

I have got a problem with adding / updating models in ListStore. On some app event I want to add a BeanModel instance produced from BeanModelFactory to store. If this produced model is already in store I want to update it in the store rather than add it again. So i wanted to user store.contains() method to check it model that came with event is already in my store. But this does not work. Equals() method from entity is not called.

So my question is: Does equals() method from entity class is used in instance of bean model produced by BeanModelFactory or there is some other method to handle such situation?

If some of this is not understandable I will post some code of my app.

Regards,
Stogi

zdarsky
6 Aug 2009, 11:43 PM
The generated BeanModel uses hashcode and equals from the bean supplied.

public boolean equals(Object obj) {
if (obj instanceof BeanModel) {
obj = ((BeanModel)obj).getBean();
}
return bean.equals(obj);
}
public int hashCode(){
return bean.hashCode();
}

Martin

stogi
6 Aug 2009, 11:50 PM
Hi!

Thanks for reply!

What you wrote is true. I checked it (beanmodel.equals(something)) and it was in equals method of entity (some sysout.print log). But when I use store.contains(beanmodel), the equals() method of entity is not called. And this is weird for me because store.contains() calls contains() method from ArrayList that holds all models in store. Both objects are not null so equals() should be called.

Any ideas?

Regards,
Stogi

zdarsky
6 Aug 2009, 11:52 PM
No, I don't. I use the very same functionality and it works for me...
I use GWT 1.7.0 and GXT 2.0.1

stogi
6 Aug 2009, 11:59 PM
Could you paste some code samples of your working example? I would be grateful :).

Regards,
Stogi

zdarsky
7 Aug 2009, 12:01 AM
QuestiongroupBO group is my bean object...

BeanModelFactory factory = BeanModelLookup.get().getFactory(QuestiongroupBO.class);

BeanModel questionaireGroupModel = factory.createModel(group);

if (store.contains(questionaireGroupModel)) {
....

stogi
7 Aug 2009, 12:07 AM
And how you initialize store object? Maybe this is my problem.

zdarsky
7 Aug 2009, 12:19 AM
MemoryProxy<List<QuestiongroupBO>> proxy = new MemoryProxy<List<QuestiongroupBO>>(new ArrayList<QuestiongroupBO>());



BeanModelReader reader = new BeanModelReader();



ListLoader<ListLoadResult<BeanModel>> loader = new BaseListLoader<ListLoadResult<BeanModel>>(proxy, reader);




GroupingStore<BeanModel> store = new GroupingStore<BeanModel>(loader);

stogi
7 Aug 2009, 12:22 AM
Thank you for your help! I will check this.

Regards,
Stogi

stogi
7 Aug 2009, 1:12 AM
Hi!

Problem was at my side. Wrong logical condition in equals(). Thanks for your help.

Best regards,
Stogi