PDA

View Full Version : Why ext doesn't view the proxy read method



anto75
15 Feb 2012, 1:48 AM
Hi guys,
I'm new with ExtJS 4.0.7 and I'm trying to porting a store manager management from extjs3.

At the moment I'm able to call a java action for read data (with dynamic model)... BUT I'am not enable to read the response because my js catch in a "reader.read is not a function" exception.

This is my code (probable is optimizable but I'm working in incremental way):


Ext.define('Sbi.extjs.chart.data.Store', {
extend: 'Ext.data.Store',
requires: 'Sbi.extjs.chart.data.Model',
model: 'Sbi.extjs.chart.data.Model',
alias2FieldMetaMap: null,
refreshTime: null,
dsLabel: null,
proxy: null

, constructor: function(config) {
...
this.proxy = Ext.apply(this.createProxy(proxyUrl),{});
....

return this;
}
...
, createProxy: function(url){
var proxy = new Ext.data.proxy.Ajax({
url: url,
type: 'ajax',
format: 'json',
method: 'GET' //POST or GET
reader: {
type:'json',
root: 'rows',
totalProperty: 'results'
// successProperty: 'success'
}
});
return proxy;
}


In debug (method 'processResponse' of ext-all-debug.js) I can see that the object me.getReader() returns un object with only my properties setting (type, root,..), so the instruction 'result = reader.read(me.extractResponseData(response));' breaks all.

In the documentation I read that "AjaxProxy can be configured to use any type of Reader to decode the server's response. If no Reader is supplied, AjaxProxy will default to using a JsonReader. " So I beleve that the method should be already defined. I'm wrong?

Someone could help me ?? It' s very important!!!

Thanks in advance,

Antonella

mitchellsimoens
15 Feb 2012, 5:56 AM
You would need to set the model config on the proxy. In the constructor of Ext.data.proxy.Proxy, i does this check:


if (this.model !== undefined && !(this.model instanceof Ext.data.Model)) {
this.setModel(this.model);
}

And in setModel it executes setReader which is where the reader is created but this all hinges on the model being set on the proxy.

anto75
15 Feb 2012, 6:54 AM
Hi Mitchell,
thank you very much for your answear...

But now I have another problem ! :(

Following your suggestion I create a new instance of my model in the store js class and I add it to my proxy... BUT I saw that I have some problems when I call the this.callParent() instruction.
The exception that I have is "fields is undefined" when it executes the method buildFieldExtractors{fields = me.getFields(), // it return undefined
ln = fields.length,
...}

Next my new code:


Ext.define('Sbi.extjs.chart.data.Store', {
extend: 'Ext.data.Store',
require: 'Sbi.extjs.chart.data.Model',
// model: 'Sbi.extjs.chart.data.Model',
model: null,
fields: null,
alias2FieldMetaMap: null,
refreshTime: null,
dsLabel: null,
proxy: null

, constructor: function(config) {
this.dsLabel = config.datasetLabel;
var c = Ext.apply(config || {});

c.groupers = {};
c.filters = {};
c.sorters = {};

Ext.apply(this, c);
...
var proxyUrl = Sbi.config.serviceRegistry.getServiceUrl({serviceName: 'GET_CHART_DATA_ACTION'
, baseParams:params
});

this.proxy = Ext.apply(this.createProxy(proxyUrl),{});

var modelConfig = {};
modelConfig.proxy = this.proxy;
this.model = new Sbi.extjs.chart.data.Model(modelConfig); // the new instruction
this.fields = this.model.fields; // it's a test but doesn't work again
this.refreshTime = config.refreshTime;
delete config.refreshTime;
this.callParent(this, c); // it goes on error
return this;
}
...
...
, createProxy: function(url){

var proxy = new Ext.data.proxy.Ajax({
url: url,
type: 'ajax',
format: 'json',
method: 'POST'
// , extraParams: {StartDate: ''}
, reader: {
type:'json'
, root: 'rows'
, idProperty: 'id'
, totalProperty: 'results'
, successProperty: 'success'
/*, read: function(response){
var result = Ext.decode(response.responseText);
var toReturn = {};
//toReturn.records = result.rows;
toReturn.records =this.model;
toReturn.total = result.results;
toReturn.success = true;
toReturn.fields = this.model.fields
return toReturn;
}
*/
}
});
return proxy;
}


And now the model code:



Ext.define('Sbi.extjs.chart.data.Model', {
extend: 'Ext.data.Model',
fields: null,
proxy: null

, constructor: function(config) {

var c = Ext.apply(config || {});
Ext.apply(this, c);

this.callParent(this, c);

this.fields = ["recNo",{"type":"string","header":"name","dataIndex":"column_1","name":"column_1"},{"type":"int","header":"data1","dataIndex":"column_2","name":"column_2"},{"type":"int","header":"data2","dataIndex":"column_3","name":"column_3"},{"type":"int","header":"data3","dataIndex":"column_4","name":"column_4"},{"type":"int","header":"data4","dataIndex":"column_5","name":"column_5"},{"type":"int","header":"data5","dataIndex":"column_6","name":"column_6"}];
this.prototype = {}; //it's a test
this.prototype.idProperty = 'id';
this.prototype.fields = this.fields;

return this;
}

});


Could you help me again about the constructor call? Where is bettere to do it? Why it search me.getFields() and an undefined is returned ???

Thank you again,

Antonella

mankz
15 Feb 2012, 2:05 PM
Hmm, you're doing lots of strange stuff in your constructor that I don't understand. Anyway, this is how you should call the superclass:


this.callParent(arguments);

anto75
16 Feb 2012, 12:59 AM
Hi guys,
thank you again for your reply. With your last suggestion I saw that the script goes on... but not to the end...

Debugging the ext-all-debug.js file I saw that the proxy calls the java action for get all data and than tries to load they... but I got a new exception:
"listener.fireFn is undefined" when it tries to do :
" if (listener && listener.fireFn.apply(listener.scope || me.observable, args) === false) {"


At the moment I already defined a callback method on the load of store:


, loadStore:

function(){this.load({params: {}, callback: function(){alert("callback on load"); this.ready = true;}, scope: this, add: false

});
}

However, I tried to add the load listener but nothing change :(
"
, listeners: {'load': function(store, records, successful) {alert(successful);}}
"
Do you know which method it searches to fire? Is necessary to add some listeners on the store?

Thanks,

Antonella

anto75
16 Feb 2012, 3:42 AM
Hi,

I solved this bug too... the problem was a my error in the calling of a method on an object not again defined :">

So I can close this thread.

Thanks to all,

Antonella