PDA

View Full Version : Binding List issue?



Lada
4 Dec 2010, 4:00 PM
Hi all!
I've tryed to bind a List<MyObject> to a Grid<BeanModel>. If I modify an existing grid row everythng is working fine and the List<MyObject> model sees the changes. But if I try to add or delete a row, commitChanges() method called on grid's ListStore seems not to work because the model doesnt'see the changes. May be I have to do something else when adding or deleting?

Thanks in advance!

Lada

sven
5 Dec 2010, 5:54 AM
commitChanges does not handle adds or removes. It just handles "changes" within records of the models.

pejo
5 Dec 2010, 7:52 AM
Thanks for you reply!
Ok, so how can I bypass this behaviour? I've noticed that calling getModels() on the store returns the expected list of beans (I've just to convert them of course). Is this the best way to update the model or there is a cleaner approach?

Lada

sven
5 Dec 2010, 8:00 AM
Store fires a Store.Add event and a Store.Remove event on add/remove. You can listen to that and updaet your database directly or save these informations somewhere.

Lada
7 Dec 2010, 9:33 AM
Ok. To let commitChanges handle the remove operation as if it was an update, I added a "flagDeleted" property to the bean (default to "N"). When the user clicks the remove button the flag value is changed and the grid filtered:



public void handleEvent(MessageBoxEvent be) {
if (be.getButtonClicked().getItemId().equals(Dialog.YES)) {
BeanModel bm = grid.getSelectionModel().getSelectedItem();
bm.set("flagDeleted", "S");
//grid.getStore().remove(bm);
grid.getStore().filter("flagDeleted", "N");
};
}
};


It seems to work but if a rejectChanges is performed, the underlying bean isn't rolled back even if that's an update operation at all. What's wrong with this pattern?

Thanks!

sven
7 Dec 2010, 9:40 AM
It seems to work but if a rejectChanges is performed, the underlying bean isn't rolled back even if that's an update operation at all. What's wrong with this pattern?

Please post a fully working testcase implemnting EntryPoint for this. What you are you doing exactly?

Lada
8 Dec 2010, 2:38 AM
The attach contains a simple test case, I hope it matches your request.
As I press the "Remove" button, I want to mark the selected entry as deleted so I change the flag on the underlying bean and then apply a filter in order to hide the removed entry. If I press the "Reset" button, I expect that the changes on the "deleted" bean are rollbacked and I would like to see it again in the grid through the applied filter "N". But if you press the "Print" button you can see that rejectChanges has no effect and the changes are permanent.

I hope I was clear, thanks!

sven
8 Dec 2010, 2:45 AM
commitChanges does not handle adds or removes. It just handles "changes" within records of the models.


btnRemove.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
Stock stock = grid.getSelectionModel().getSelectedItem();
if (stock != null) {
Record r = grid.getStore().getRecord(stock);
r.set("flagDeleted", "Y");
}
grid.getStore().filter("flagDeleted", "N");
}
});

You need to set in on the Record, so it can be rejected or commited.

Thanks for taking the time to put together this code. Not many people do this.

Lada
8 Dec 2010, 5:04 AM
it works of course! :D

Thanks to your ready answers, it's the first time that I can see this, 10 points gained by GXT support team!

sven
8 Dec 2010, 6:43 AM
it's the first time that I can see this,
What you can see for the first time?

Lada
8 Dec 2010, 12:13 PM
I've found this GXT forum really helpful thanks to ready answers...I believe it isn't the same among other forum