PDA

View Full Version : JSON Reader: this.recordType gives null value



mango
8 Mar 2009, 8:18 PM
Hi,

I am developing a sample grid using the technologies Java, Spring and Ext JS grid.

My requirement is, when the page is loaded, I am loading the grid with http proxy call.

Http proxy will be giving the response, but I am getting the following error:

readRecords()(Object records=Object)ext-all-debug.js (line 11532)
read()(Object tId=0 status=200 statusText=OK)ext-all-debug.js (line 11494)
loadResponse()(Object params=Object request=Object reader=Object, true, Object tId=0 status=200 statusText=OK)ext-all-debug.js (line 11335)
getViewWidth()(function(), Object events=Object conn=Object useAjax=true, [Object params=Object request=Object reader=Object, true, Object tId=0 status=200 statusText=OK 0=Object 1=true 2=Object], undefined)ext-base.js (line 9)
handleResponse()(Object tId=0 status=200 statusText=OK)ext-all-debug.js (line 5318)
getViewWidth()(Object tId=0, Object scope=Object argument=Object timeout=30000, undefined)ext-base.js (line 10)
getViewWidth()()ext-base.js (line 10)
f = Record.prototype.fields, fi = f.items, fl = f.length;

I found this error in the firebug.

below is my code:


var recordType = Ext.data.Record.create([
{name: 'id', mapping: 'id'},
{name: 'medication', mapping: 'medication'},
{name: 'dose', mapping: 'dose'},
{name: 'route', mapping: 'route'},
{name: 'freq', mapping: 'freq'},
{name: 'lasttaken', type: 'date', dateFormat: 'm/d/Y', mapping: 'lasttaken'},
{name: 'indication', mapping: 'indication'},
{name: 'flag', mapping: 'flag'}
]);
var homeReader = new Ext.data.JsonReader(
{
root: 'records.data',
id: 'id',
successProperty: 'records.success',
totalProperty: 'records.results'
}, recordType
);


var httpProxy = new Ext.data.HttpProxy({url: url); //calling servlet

httpProxy.getConnection().on('requestexception', requestFailed);
var homeDataStore = new Ext.data.JsonStore({
proxy: httpProxy,
reader: homeReader
});

homeDataStore.on('loadexception', loadFailed);

homeDataStore.on('load', loadSuccessful);

homeDataStore.load({params:{start:0, limit:10}, callback: loadAndShowGrid});

function requestFailed(connection, response, options) {

Ext.MessageBox.alert('Error Message',
"Please contact support with the following: " +
"Status: " + response.status +
", Status Text: " + response.statusText);
}

function loadFailed(proxy, options, response, error) {
var object = Ext.util.JSON.decode(trim(response.responseText));
var errorMessage = "Error loading data.";

Ext.MessageBox.alert('Error Message', errorMessage);
}

function loadSuccessful(store, recordArray, options) {
}



and the response from the call is

{"records":{"data":[{"dose":"500 mg""freq":"Daily","id":0,"indication":"Daily","lasttaken":"10/25/2008","medication":"Lioxcin""route":"IP"},{"dose":"100 mg""freq":"Daily","id":1,"indication":"Daily","lasttaken":"10/26/2008","medication":"AAA""route":"PO"}],"message":"Successfully retrieved persons","success":true,"results":2}}


in the loadexception method, result is parsed successfully.

I have been trying this to solve, but I could not. I do not know where I went wrong here.

Please help me in solving this problem.

Thanks in advance.

Sri

shibubh
8 Mar 2009, 8:36 PM
var homeReader = new Ext.data.JsonReader(
{
root: 'records.data',
id: 'id',
successProperty: 'records.success',
totalProperty: 'records.results'
}, recordType
);




change into




var homeReader = new Ext.data.JsonReader(
{
root: 'data',
id: 'id',
successProperty: 'success',
totalProperty: 'results'
}, recordType
);