PDA

View Full Version : Store and RPC failure



naruponk
31 Mar 2009, 5:19 AM
I have a conceptual question about Stores for data binding.

If i got it right when i want to add update or delete the store will manage it and i can handle the events and call via proxy or any other interface for the RPC call and get back the results.

this is great but what happen when the RPC fail? in this case the store state is already include the new data but the backend DB doesnt. it become very hard to manage those exceptions.

Since i want to use the stores with the integration with the UI controls. is it possible to call first the RPC then get back the results and then update the store on success. it need to be somthing like transaction with the option to rollback.

please advise

Thanks inadvance

the.jxc
25 May 2009, 9:00 PM
Heya. I'm looking for info on the same problem.

I have a grid where multiple rows can be modified, then committed. When some fail, I don't want to discard the changes with a store.reload(). I want something smarter.

I'll keep looking. :)

the.jxc
26 May 2009, 4:50 PM
Here is the simplest way that I found to do this. In hindsight, it's really obvious. Here's my override which adds a writeChanges method to Store.


// Extend Store to have a method which will callback so that we can write each
// modified record, without actually finalising the commit until later.
//
Ext.override (Ext.data.Store, {
/**
* Fires the update event with "WRITE" as the parameter. Does NOT COMMIT
* ANY CHANGES. When you receive your Ajax response(s), then for each record
* successfully written, you simply call <record>.commit() to finalise
* the change in the local store and grid.
*/
writeChanges : function(){
var m = this.modified.slice(0);
for (var i = 0, len = m.length; i < len; i++){
this.fireEvent("write", this, m[i]);
}
},
});Give the store a 'write' handler...


'write' : function (store, record) {
yourCustomAjaxAPI (with, whatever, parameters, you, use...);
},And finally, in your Ajax response hander somewhere...


record.commit ();Note: In order to get access to your record at Ajax response callback time, you probably need to store it as an attribute on your request.

For deletes, it's even simpler. When the user clicks the delete button, just invoke your AjaxAPI directly. On the callback when the Ajax response is received, just call


store.remove (record).The Ajax DB interaction API is the painful bit. It seems there's no real SIMPLE option out there for people who just want basic glue. You can use CakePHP, or ColdFusion... but it's all a bit heavyweight if all your really want is to get a few rows in and out of a database in JSON format. I'm working on something lightweight called Jarvis which consists of half a dozen PL files which currently does:

- Authentication & Security (DB or LDAP),
- Data fetch (JSON or XML)
- Data update/delete (JSON or XML)

It's designed to work with ExtJS and JSON, but I've also gotten it going with Adobe Flex using XML. I guess I'll post it somewhere one day.