PDA

View Full Version : Reader is null in Store with JsonReader with same configuration



SUPER_X
7 Oct 2009, 7:27 AM
Hello,

The situation is like this, there's a TabPanel wich contains initially contains 1 tab wich is a Grid with Items. This items have actions that expand into a new tab with a subItems grid, wich has an items combo (on the tbar) that can also change the content of the subitems store, the store for the combo, the value selected in that combo and the subitems store for the grid all need to be done.

The code down below shows a reduced way of how I'm doing stuff, some things got cut but are obvious, or don't need to be mentioned.
The site works as it should, except in this case, if I expand into a subItems grid, then I close that grid, and then try to expand again into subItems grid, then I'll receive this error coming from the line on the subitems grid where it says "this.store.load()":



reader is null
anonymous("read", Object name=rs, Object a=ejes.listadoJSON, Object name=reader, function(), Object baseParams=Object removed=[0] autoDestroy=true, Object params=Object)ext-all-debug.js (línea 32914)
anonymous("read", Object name=rs, Object a=ejes.listadoJSON, Object name=reader, function(), Object baseParams=Object removed=[0] autoDestroy=true, Object params=Object)ext-all-debug.js (línea 32408)
anonymous("read", Object name=rs, Object params=Object)ext-all-debug.js (línea 30838)
anonymous(Object params=Object)ext-all-debug.js (línea 30724)
anonymous()listado.js (línea 123)
anonymous(Object id_eje=1 id=PanelDimensiones)ext-all-debug.js (línea 13830)
anonymous()ext-base.js (línea 7)
anonymous()ext-base.js (línea 7)anonymous()ext-base.js (línea 7)
anonymous()ext-base.js (línea 7)
anonymous()ext-base.js (línea 7)
anonymous()ext-base.js (línea 7)
anonymous("PanelDimensiones", Object id_eje=1 id=PanelDimensiones)AppTabPa...ncipal.js (línea 25)
anonymous("PanelDimensiones", Object id_eje=1 id=PanelDimensiones)AppTabPa...ncipal.js (línea 42)
anonymous(Object initialConfig=Object id=PanelEjes, Object id=1 data=Object json=Object store=Object, "icon-arrow-out", Object name=row value=0, 1)listado.js (línea 65)
anonymous(Object scope=Object options=Object)ext-all-debug.js (línea 2124)
anonymous([Object scope=Object options=Object 0=Object], function(), Object name=E)ext-base.js (línea 7)
anonymous()ext-all-debug.js (línea 2122)
anonymous()ext-all-debug.js (línea 1809)
anonymous(Object browserEvent=Event mouseout button=0 type=mouseout, div.ux-row-action-item)Ext.ux.g...ctions.js (línea 466)
h(Object browserEvent=Event mouseout button=0 type=mouseout)ext-all-debug.js (línea 2463)
chrome://firebug/content/blank.gif if (typeof(params[reader.meta.root]) === 'object') {\r\next-all-debug.js (línea 32914)



My only guess would be that somehow the reader gets an id and doesn't get destroyed when I close the tab, so when I try to reopen it, I can't create it again. But the id attribute on the reader is the attribute for each record, not for the Reader, and anyway, it should be destroyed.



App.ItemStore = function(config) {
var config = config || {};
Ext.applyIf(config,{
autoDestroy: true,
url: APP_AJAX_URL,
baseParams: {action: 'items.jsonlist'},
reader: new Ext.data.JsonReader({
root: 'data',
id: 'id_item',
totalProperty: 'totalRecords'
},[
{name: 'id_item', type: 'int'},
{name: 'descripcion'}
])
});
App.ItemStore.superclass.constructor.call(this,config);
};
Ext.extend(App.ItemStore,Ext.data.Store);

App.ItemsCombo = Ext.extend(App.ComboBox,{
store: new App.ItemsStore()
// other config options
});

// ----

App.ItemsGrid = Ext.extend(Ext.grid.EditorGridPanel,{
title: 'Items'
},
initComponent: function(){
this.store = new App.ItemsStore({
storeId: 'itemsStore',
baseParams:{
a: 'items.jsonlist',
start: 0,
limit: APP_PAGE_SIZE
},
autoLoad: false
});
Ext.apply(this,{store: this.store, etc});
this.store.load();
App.ItemsGrid.superclass.initComponent.call(this);
}
);

// ---

App.SubItemsGrid = Ext.extend(Ext.grid.EditorGridPanel,{
title: 'Items'
},
initComponent: function(){
var grid = this;
this.store = new App.SubItemsStore({
storeId: 'subitemsStore',
baseParams:{
a: 'subitems.jsonlist',
start: 0,
limit: APP_PAGE_SIZE
},
autoLoad: false
});
this.itemsCombo = new App.ItemsCombo({
id: 'itemsComboSubItemsGrid'
});
Ext.apply(this,{
store: this.store
// other options
});
this.store.load();
var ic = this.itemsCombo;
ic.store.on('load',function(){
ic.setValue(grid.id_item);
});
this.itemsCombo.store.load();
this.store.load();
App.ItemsGrid.superclass.initComponent.call(this);
}
);

App.MainTabPanel = Ext.extend(Ext.TabPanel, {
region:'center',
plugins: new Ext.ux.TabCloseMenu(),
loadTab: function(id,config){
var config = config || {};
config.id = id;
config.tabPanelPrincipal = this;
config.closable = true;
switch(id){
case 'ItemsPanel': return new App.ItemsGrid(config); break;
case 'SubItemsPanel': return new App.SubItemsGrid(config); break;
}
},
moveToTab: function(id,config){
var tab = this.getComponent(id);
if(tab){
this.setActiveTab(tab);
this.scrollToTab(tab);
if(config) tab.reloadStores(config);
}
else{
var objeto = this.loadTab(id,config);
tab = this.add(objeto);
this.setActiveTab(tab);
}
return tab;
}
});



Thanks for reading.

Condor
7 Oct 2009, 7:31 AM
You can't do this:

App.ItemsCombo = Ext.extend(App.ComboBox,{
store: new App.ItemsStore()
// other config options
});
because it would mean that there is only one 'store' for all App.ItemsCombo instances.

You need to assign the store in the constructor or in initComponent and not in the prototype.

As a general rule: Objects don't belong in a prototype (this includes Ext.extend and Ext.override).

SUPER_X
7 Oct 2009, 7:33 AM
Thank you very much for the quick answer =)