PDA

View Full Version : Parsing xml exception response with DataStore...



bzborow1
15 Feb 2011, 10:24 AM
Hi all,

Basically I have a DataStore that properly loads an XML response from a backend web service I've created. The problem is, my web service also pre-formats exceptions into an xml file, similar to:



<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<CplError xmlns="http://model.agmaf.agr.gc.ca/oxm/CPLErrors">
<exceptionType>java.lang.ClassCastException</exceptionType>
<exceptionMessage>java.lang.Integer</exceptionMessage>
</CplError>


Is there an easy way to specify something like an exception reader as well? I'd like to read the xml response if its correct into the data grid, but do something entirely different if this <CPLERROR> is found. Is this possible?



this._twnStore = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
method: 'GET',
disableCaching:false,
url: this.getParam('cplUrl')
}),
reader: new Ext.data.XmlReader({
record: 'result',
totalRecords: 'totalRecords'

},[
{name: 'objectid', mapping: 'properties:nth(1) > value'},
{name: 'qscode', mapping: 'properties:nth(2) > value'},
{name: 'section', mapping: 'properties:nth(3) > value'},
{name: 'township', mapping: 'properties:nth(4) > value'},
{name: 'range', mapping: 'properties:nth(5) > value'},
{name: 'meridian', mapping: 'properties:nth(6) > value'},
{name: 'adate', mapping: 'properties:nth(7) > value'},
{name: 'inadate', mapping: 'properties:nth(8) > value'},
{name: 'MinX', mapping: 'extent > minx'},
{name: 'MinY', mapping: 'extent > miny'},
{name: 'MaxX', mapping: 'extent > maxx'},
{name: 'MaxY', mapping: 'extent > maxy'}
])
});





/**
* DATA STORE configuration.
*/
this._store.load({
params: this._params
});
this._store.on({
'load' : {
//store is loaded, now you can work with its records.
fn: function(store, records, options) {
this.setTitle("Search Result(s) - " + store.getCount() + " result(s) found");
},
scope: this
},
'loadexception': {
//consult api for the proxy used for the actual arguments.
fn: function(obj, options, response, e) {
console.trace();
Ext.Msg.show({
title: response.status + " " + OpenLayers.i18n('err.connect.title'),
msg: OpenLayers.i18n('err.connect.msg'),
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
console.info("obj = ", obj);
console.info("options = ", options);
console.info("response = ", response);
console.info("error = ", e);
this.destroy();
},
scope: this
},
'exception': {
fn: function(misc) {
Ext.Msg.show({
title: Openlayers.i18n('err.connect.title'),
msg: 'There was a problem searching the Parcel Search Service. Please try again later.',
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
})
},
scope: this
}
});

bzborow1
16 Feb 2011, 7:26 AM
Hi guys. Been playing around with this some more and still can't get it to work. Is this not feasible in extjs? Should I abandon the store.load idea with an Ext.Ajax.request?

bzborow1
16 Feb 2011, 7:55 AM
I guess I found a hack workaround on the server side. When my spring app throws an exception I just pass along an httpstatus error code and the store picks it up. It's not really what I'm looking for, as I'd like to more properly capture a server-side exception, sent as xml, within an extjs web application.