PDA

View Full Version : Ext Store bug?



livensnick
25 Nov 2011, 12:16 AM
Hi all,

I have the following store :

Ext.define('be.rwo.dataviewer.store.Layers', {
extend: 'Ext.data.Store',
model: 'be.rwo.dataviewer.model.Layer',


autoLoad: true,
sorters: {
property: 'id',
direction: 'ASC'
}
});


And the following model :

Ext.define('be.rwo.dataviewer.model.Layer', {
extend: 'Ext.data.Model',
fields: ['id', 'screenName', 'wms', 'geoserverUrl']
});


This is the json returned from a rest service :


[{"id":10,"type":null,"attributes":null,"source":null,"roles":[],"creationDate":null,"tableName":null,"style":null,"screenName":"Landschappen","labelStyle":null,"opacity":null,"minimumScale":null,"maximumScale":null,"wms":"landschap","resultAttributes":[],"zIndex":null,"geoserverUrl":"http://srv3.rwo.be:8180/gs_dataviewer"},{"id":5,"type":null,"attributes":null,"source":null,"roles":[],"creationDate":null,"tableName":null,"style":null,"screenName":"Archeologische sites","labelStyle":null,"opacity":null,"minimumScale":null,"maximumScale":null,"wms":"archeologische_site","resultAttributes":[],"zIndex":null,"geoserverUrl":"http://srv3.rwo.be:8180/gs_dataviewer"}]


As you can see, there is a "geoserverUrl" and "wms" in each object returned by the rest service.
But the store doesn't set the geoserverUrl and wms value. It just sets it to null instead of the real value. But the store does set the values for "id" and "screenName"...

Any1 has seen this problem before?

Any help is appreciated.

mankz
25 Nov 2011, 1:23 AM
You have no reader setup on your store, look at some of the basic grid examples and you'll get a good idea on how it works (or the docs) :)

skirtle
25 Nov 2011, 1:26 AM
I'd be surprised if this turns out to be a bug, someone would have noticed this before.

How are you ascertaining that the values are null?

livensnick
25 Nov 2011, 1:30 AM
I'd be surprised if this turns out to be a bug, someone would have noticed this before.

How are you ascertaining that the values are null?

When I retrieve the store, I just look at the data it contains ;)

skirtle
25 Nov 2011, 1:30 AM
You have no reader setup on your store, look at some of the basic grid examples and you'll get a good idea on how it works (or the docs) :)

I assume the proxy and reader have just been cut from the posted code? Not clear how else the data could successfully load the id and screenName from a RESTful source...

livensnick
25 Nov 2011, 1:33 AM
You have no reader setup on your store, look at some of the basic grid examples and you'll get a good idea on how it works (or the docs) :)

Sorry, what I didn't mention is that I change the store proxy dynamically with this code :


setStoreProxy: function(storeName, restUrl) {
var store = this.getStore(storeName);
store.setProxy({
type: 'ajax',
api: {
read: restUrl
},
reader: {
type: 'json'
}
});
store.load();
}

skirtle
25 Nov 2011, 1:34 AM
When I retrieve the store, I just look at the data it contains ;)

Please be specific. What exactly are you doing?

livensnick
25 Nov 2011, 1:37 AM
Please be specific. What exactly are you doing?

When you debug javascript through google chrome developer tools, you can see what a store contains.
Or you could just do like : console.debug(myStore.data.items) which contains the data loaded

livensnick
25 Nov 2011, 1:40 AM
I made a temporary hack which does fill in the fields I require :


var layerStore = this.getStore('be.rwo.dataviewer.store.Layers');
//Temporary hack because store doesn't autobind "geoserverUrl" and "wms"
Ext.Ajax.request({
url: locations.getUrl('rest') + '/layer/' + this.selectedTheme.id,
method: 'GET',
success: function(response) {
layerStore.loadData(Ext.JSON.decode(response.responseText));
}
});

skirtle
25 Nov 2011, 1:58 AM
When you debug javascript through google chrome developer tools, you can see what a store contains.
Or you could just do like : console.debug(myStore.data.items) which contains the data loaded

This doesn't really answer my question. What I want to know is exactly where in the debug output you are seeing that the field value is null. Inspecting the store in this way could be very misleading as there can be all sorts of properties accessible via the debugger that don't actually have any significance.

A more reliable technique would be something like this:


console.log(store.first().get('wms'));

I assume you captured the JSON using Chrome's Network tab?

livensnick
25 Nov 2011, 2:12 AM
I retrieved the wms and geoserverUrl values like this (but both were always null) :



for ( var i = 0; i < layerStore.getCount(); i++ ){
var layerAttr = layerStore.getAt(i).data;
if ( layerAttr.wms == wms ){
url = locations.getUrl('proxy') + '?url=' + layerAttr.geoserverUrl;
}
}


I captured JSON through both just surfing to the rest service, and throught he network tab ;)

skirtle
25 Nov 2011, 2:58 AM
Going to the URL directly is usually sufficient but the only way I trust is to inspect it in the Network tab. Theoretically they're the same but you can get subtle differences if the parameters or headers don't match exactly.

It would be interesting to compare the log output from the following against the original JSON:


for ( var i = 0; i < layerStore.getCount(); i++ ){
var layerAttr = layerStore.getAt(i).data;

console.log(layerAttr);

if ( layerAttr.wms == wms ){
url = locations.getUrl('proxy') + '?url=' + layerAttr.geoserverUrl;
}
}

This also seems like an overly complicated way to set the variable url. Wouldn't it be easier to do something like this?


var record = layerStore.findRecord('wms', wms);

if (record) {
url = locations.getUrl('proxy') + '?url=' + record.get('geoserverUrl');
}

I'd also be inclined to throw some URL encoding at that last part, once you've figure out this null issue.

livensnick
25 Nov 2011, 3:57 AM
The JSON I pasted is the one from the Network tab ;)
And the code you pasted about setting the url is really handy. Thanks for that :)

But still stuck on the store thingy. I really don't know what's going wrong..
JSON is correct, model has correct fields, only 2 fields get set .. Seems like a bug to me

skirtle
25 Nov 2011, 4:12 AM
What did the extra logging I suggested output?

Which ExtJS version are you using? If you aren't on 4.0.7 it might be worth trying an upgrade.

The only thing that is even slightly atypical about your setup is that you're calling setProxy. Are you able to hardcode a proxy onto the store or model just for testing purposes?

If it is a bug then you should be able to put in some breakpoints, follow it through and observe where the problem occurs. As I mentioned before, I'd be surprised if it's a bug in the library, randomly throwing away half of your fields seems like an odd thing to do. The only way I can think of that such a thing might happen is if an exception were thrown and swallowed part-way through the processing but I can't imagine why that would happen.

livensnick
25 Nov 2011, 4:46 AM
When hardcoding a proxy. It fills the fields fine..
So now the problem is, what is wrong with setting the proxy after store is created, and load data?

I'll post a solution if I find one ^^

skirtle
25 Nov 2011, 5:04 AM
Now I'm leaning towards it being a bug in the library... There were proxy problems in earlier versions but I haven't heard of anything in 4.0.7.

Both the store and the model have a setProxy() method. Either one should be sufficient but have you tried both?

livensnick
25 Nov 2011, 5:25 AM
Now I'm leaning towards it being a bug in the library... There were proxy problems in earlier versions but I haven't heard of anything in 4.0.7.

Both the store and the model have a setProxy() method. Either one should be sufficient but have you tried both?

I didn't try the setProxy of the model before you brought it up. But this one failed too, same problem.
I'll just keep the workaround until there is a fix =)

Thanks for all the help skirtle ;)