View Full Version : Binding List issue?
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
commitChanges does not handle adds or removes. It just handles "changes" within records of the models.
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
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.
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!
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?
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!
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.
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!
it's the first time that I can see this,
What you can see for the first time?
I've found this GXT forum really helpful thanks to ready answers...I believe it isn't the same among other forum
Powered by vBulletin® Version 4.1.5 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.