Thank you for reporting this bug. We will make it our priority to review this report.
-
Ext JS Premium Member
[OPEN-1281] No exception event launched for DirectProxy read with success:false
Ext version tested:
Adapter used:
Browser versions tested against:
- FF3 (firebug 1.3.0.10 installed)
Operating System:
Description:
- When sending back json from the server with success:false to a read action of a DirectProxy used with a grid, the exception event is not launched.
Debugging already done:
- Found the problem in onRead method of DirectProxy :
Code:
onRead : function(action, trans, result, res) {
var records;
try {
records = trans.reader.readRecords(result);
}
catch (ex) {
this.fireEvent("loadexception", this, trans, res, ex);
this.fireEvent('exception', this, 'response', action, trans, res, ex);
trans.request.callback.call(trans.request.scope, null, trans.request.arg, false);
return;
}
this.fireEvent("load", this, res, trans.request.arg);
trans.request.callback.call(trans.request.scope, records, trans.request.arg, true);
}
readRecord Code from the JSON Writer is:
Code:
readRecords : function(o){
this.jsonData = o;
if(o.metaData){
this.onMetaChange(o.metaData);
}
var s = this.meta, Record = this.recordType,
f = Record.prototype.fields, fi = f.items, fl = f.length, v;
var root = this.getRoot(o), c = root.length, totalRecords = c, success = true;
if(s.totalProperty){
v = parseInt(this.getTotal(o), 10);
if(!isNaN(v)){
totalRecords = v;
}
}
if(s.successProperty){
v = this.getSuccess(o);
if(v === false || v === 'false'){
success = false;
}
}
return {
success : success,
records : this.extractData(root, true),
totalRecords : totalRecords
};
}
As we can see, it doesn't throw an exception when success is false, instead returning it in the result.
The onWrite method, however, manages exceptions correctly:
Code:
onWrite : function(action, trans, result, res, rs) {
var data = trans.reader.extractData(trans.reader.getRoot(result), false);
var success = trans.reader.getSuccess(result);
success = (success !== false);
if (success){
this.fireEvent("write", this, action, data, res, rs, trans.request.arg);
}else{
this.fireEvent('exception', this, 'remote', action, trans, result, rs);
}
trans.request.callback.call(trans.request.scope, data, res, success);
}
Something similar should be done for onRead.
If it's not a bug and is intended, would you care to explain why the success property have no effect on DirectStores' read actions and also tell me if there is a standard way of managing success:false returns when loading the store ?
Thanks.
Frederick Deslandes
Web applications developer
Boreal Informations Strategies
-
This does look like an oversight and should be in place for the onRead method as well.
-
Ext JS Premium Member
Thanks.
Here is my temporary fix:
Code:
// Add support for success property in DirectProxy read calls
Ext.override(Ext.data.DirectProxy,
{
onRead : function(action, trans, result, res)
{
var records;
try
{
records = trans.reader.readRecords(result);
}
catch (ex)
{
this.fireEvent("loadexception", this, trans, res, ex);
this.fireEvent('exception', this, 'response', action, trans, res, ex);
trans.request.callback.call(trans.request.scope, null, trans.request.arg, false);
return;
}
if(trans.reader.getSuccess(result) === false)
{
this.fireEvent("loadexception", this, trans, res);
this.fireEvent('exception', this, 'remote', action, trans, res.result);
trans.request.callback.call(trans.request.scope, null, trans.request.arg, false);
return;
}
this.fireEvent("load", this, res, trans.request.arg);
trans.request.callback.call(trans.request.scope, records, trans.request.arg, true);
}
});
Frederick Deslandes
Web applications developer
Boreal Informations Strategies