PDA

View Full Version : Store proxy exception fired though successful



augustinas
7 May 2009, 12:19 PM
I could not find this discussed in the forum. If so, let me know.
I have an Ext.data.Store with proxy defined as:



proxy:
new Ext.data.HttpProxy({


api: {


load: '../config/op.aspx?o=0',


create: '../config/op.aspx?o=1',


save: '../config/op.aspx?o=2',


destroy: '../config/op.aspx?o=3'


}


})

These operations function successfully. When I added to perform post processing on the create, I learned that while { success:true } was returned, the createexception event was fired and not the create event.

I'm obviously misunderstanding something. Any insight would be appreciated.

VinylFox
7 May 2009, 1:21 PM
Whats your entire response look like?

augustinas
7 May 2009, 1:36 PM
I have tried both the simple:

{ success:true }
or, where I am also returning the newly inserted record from the server database:

{ success:true, rows: [{'id':'3000015','LocNo':'A222','ServiceNo':'02.45','AcctNo':'001-400-2','LocName'
:'2a','LocDescription':'sdfsdafdsfas fsdasafsfsfa'}]}
I can format however is required. Below is the Store definition. I appreciate any insight you can provide. This is from an web app I started building with extJS 2.2 in December.




page.locStore = new Ext.data.Store({
fields: page.locFields
, baseParams: { 'g': '0' }
, id: 'id'
, url: '../config/op.aspx?o=0',
, autoLoad: true
, reader: new Ext.data.JsonReader({
root: 'rows',
id: 'id'
}, [
'id'
, 'LocNo'
, 'ServiceNo'
, 'AcctNo'
, 'LocName'
, 'LocDescription'
])

, proxy: new Ext.data.HttpProxy({
api: {
load: '../config/op.aspx?o=0',
create: '../config/op.aspx?o=1',
save: '../config/op.aspx?o=2',
destroy: '../config/op.aspx?o=3'
}
})
, batchSave: false
, writer: new Ext.data.JsonWriter({
returnJson: true,
writeAllFields: true
})
, listeners: {
create: function(store, result, ex) {
// response from server when a new loc was created
//alert("create returned"); -- NEVER OCCURS
NewLocServerResponse(store, result, ex);
}
, createexception: function(directProxy, record, ex) {
//alert("createexception: " + ex.toString()); // ALWAYS OCCURS
}
, save: function(store, record, ex) {
alert("save");
}
, saveexception: function(directProxy, record, ex) {
alert("saveexception: " + ex.toString());
}
, destroy: function(store, record, ex) {
alert("destroy");
}
, destroyexception: function(directProxy, record, ex) {
alert("destroyexception: " + ex.toString());
}
, load: function(st, recs, opt) {
alert("afterload of groupDefStore count: " + recs.length);
}
, loadexception: function() {
alert("loadexception event in groupDefStore");
}
}
});

augustinas
7 May 2009, 1:47 PM
I appreciate your quick reply to my initial posting.

From Firebug I see that the server responds with the data as in my previous posts and a 200 OK. Perhaps there is more that I must do to let extJS know that the response is in JSON format?



BTW - I have your book here within reach. Nicely done!

VinylFox
7 May 2009, 2:09 PM
Did you add the 'create' event to your component?

Ill ping Chris, and see if he can chime in on this.

Glad you enjoyed the book :)

augustinas
7 May 2009, 2:25 PM
I don't understand. So, I'd have to then say No. :-|

In the code I have a javascript object named page that contains the Store in a property named locStore. This Store has listeners for the create and createexception events. The intent was that upon successfully creating a new record in the Store, the Store would invoke the proxy: create: '../config/op.aspx?o=1', passing the contents of the new record to the server which in turn would update the database. All this works fine. When the server responds with the success message I had hoped the Store's create event handler would fire. The event handler would allow further processing on the client with the new record, knowing that it has been successfully saved in the database. The issue is that the Store's createexception event is firing instead of the create event. It seems that the Store/Proxy/... is interpreting my server response as a failure instead of as a success.

augustinas
7 May 2009, 2:27 PM
If the component you were referring to is the Ext.data.Store, then yes. It has listeners for both create and createexception.

christocracy
7 May 2009, 3:32 PM
In SVN, I refactored all the events "create", "destroy", "save" events into simply "write". I found it too complex to manage all these different events.

Before I refactored these events, I noticed a bug where Store was firing "createexception" on "create" event, I think (or vice-versa). Perhaps that's what you're seeing.

So it's now "write", "beforewrite" and "writeexception". Notice the 2nd param to all these events is {String} action. You can make a switch in your handler.



/**
* @event beforewrite
* @param {Store} store
* @param {String} action
* @param {Record/Array[Record]} rs
* @param {Object} options HTTP request object. edit <tt>options.params</tt> to add Http parameters to request.
*/
'beforewrite',
/**
* @event write
* fires when server returns 200 after Ext.data.CREATE, UPDATE and DESTROY. Check the res['successProperty'] of the Response
* parameter for action's success/fail.
* in favor of this one "write" event.
* @param {Extd.data.Store} store
* @param {String} action [Ext.data.Api.CREATE|UPDATE|DESTROY]
* @param {Object} result The "data" picked-out out of the response for convenience.
* @param {Ext.Direct.Transaction} res
* @param {Record/Record[]} rs Store's records, the subject(s) of the write-action
*/
'write',
/**
* @event writeexception
* Fires when an exception occurred while writing remote-data.
* @param {Extd.data.Store} store
* @param {String} action [Ext.data.Api.CREATE|UPDATE|DESTROY]
* @param {Object} result null
* @param {Ext.Direct.Transaction} res
* @param {Record/Record[]} rs Store's records, the subject(s) of the write-action
*/
'writeexception'


Another thing, in your DataReader config:


reader: new Ext.data.JsonReader({
root: 'rows',
id: 'id' // <-- The param is called idProperty, not id
}


idProperty default is "id", so your code works anyway.

augustinas
7 May 2009, 3:44 PM
Chris, thanks so much for your quick response.
The RC1 code is calling createexception in all cases whether the server response is successful or not. I will evaluate the SVN code.