mardi 6 janvier 2015

Ext.data.operation ignores new data from server, instead uses stale records?!

I have a small test application.

- Person_default // model

- GridPerson // grid

- GridPersonModel // viewmodel

(There are other parts of the app, but I think they are not relevant to this issue.)


GridPersonModel uses the model and defines a store for the view. Very simple stuff.


In the person grid I start a new session (not sure if matters).

session:true


So ...


1. When the application starts, it loads data from the server.


2. I update a record in the database with a CLI script (100% independently from the web app).


3. When I hit the reload button in the grid pagination dock, the server responds with the fresh data. However, the data is not refreshed neither in the store, nor in the grid.


I attached a listener to the store "load" event and dug through the extjs code. I reached Ext.data.store.onProxyLoad()


In that function the following is true



Code:



Ext.util.JSON.decode(operation.getResponse().responseText).data[0].version
!=
operation.getResultSet().records[0].data.version

I also checked the records in the store in the "load" listener. Still the old data ...

In other words operation.getResultSet() data differs from the response from the server


How come?!

What could be the reason for this?!

I am scratching my head for a day now ... Please help


I am Using Ext 5.1



Code:



/**
* Created by venelin on 14-11-22.
*/
Ext.define("Arch4.model.Person_default", {
"extend": "Arch4.model.Base",
versionProperty: 'version',
"fields": [
{
"name": "age",
"type": "int"
},
{
"name": "dateCreated",
"type": "date"
},
{
"name": "lastUpdated",
"type": "date"
},
{
"name": "firstName",
"type": "string",
allowBlank: false
},
{
"name": "lastName",
"type": "string",
allowBlank: false
},
{
"type": "int",
"name": "city_id",
"reference": {
"type": "Arch4.model.City_default",
"association": "Person_default__City_default",
"role": "city",
"inverse": "people"
},
"displayField": "name"
},
{
type: 'integer',
name: 'version'
}
],
"requires": [
"Ext.data.proxy.Rest",
"Ext.data.reader.Json",
"Ext.data.writer.Json"
],
"proxy": {
"type": "rest",
"url": "http://localhost:8080/bg-enf-ext-arch/api2/person-default",
listeners: {
exception: function(proxy, request, operation, eOpts) {
Ext.Msg.alert('Exception');
request;
}
},
"reader": {
"type": "json",
"rootProperty": "data"
},
"writer": {
"type": "json"
}
},
"hasMany": [
{
"foreignKey": "person_id",
"model": "Arch4.model.Address_default",
"associationKey": "addresses",
"name": "addresses"
}
]
});




Code:



Ext.define('Arch4.view.person.GridPerson', {
extend: 'Ext.grid.Panel',
xtype: 'gridPerson',

requires: [
'Arch4.view.person.GridPersonController',
'Arch4.view.person.GridPersonModel'
],

controller: 'gridPerson',
viewModel: {
type: 'gridPerson'
},

loadMask: true,
session: true,
bind: {
store: '{list}'
},
selType: 'rowmodel',
listeners: {
select: 'onSelectRecord',
deselect: 'onDeselectRecord'
},
tbar: [{
text: 'Add person',
iconCls: 'person-add',
reference: 'btnAddRecord',
handler: 'onBtnAddRecord'
}, {
text: 'Remove Person',
iconCls: 'person-remove',
handler: 'onBtnRemoveRecord',
reference: 'btnRemoveRecord',
disabled: true
}, {
text: 'Edit person',
handler: 'onBtnEditRecord',
reference: 'btnEditRecord',
disabled: true
}],
columns: [{
text: 'id',
dataIndex: 'id'
},{
text: 'firstName',
dataIndex: 'firstName',
filter: true

}, {
text: 'lastName',
dataIndex: 'lastName',
filter: true
}, {
text: 'age',
dataIndex: 'age',
filter: true
}, {
text: 'Addresses',
xtype: 'templatecolumn',
dataIndex: 'addresses',
tpl: '<tpl for="addresses">{street}, gr/s. {city.name}<br/></tpl>'
}, {
text: 'City',
dataIndex: 'city_id',
renderer: function(value, metaData, record, rowIndex, colIndex, store, view) {
return record.getCity().get('name');
}
}, {
text: 'version',
dataIndex: 'version'
}],
features: [{
ftype: 'summary'
}],
dockedItems: [{
xtype: 'pagingtoolbar',
bind: {
store: '{list}'
},
dock: 'bottom',
displayInfo: true
}]
});


Code:



/**
* Created by venelin on 12/31/14.
*/
Ext.define('Arch4.view.person.GridPersonModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.gridPerson',

stores: {
list: {
model: 'Arch4.model.Person_default',
session: true,
pageSize: 10,
autoLoad: true,
listeners: {
load: function(store, records, successful, eOpts) {
records;
},
beforeload: function(store) {
return true;
}
}
}
}
});





Ext.data.operation ignores new data from server, instead uses stale records?!

Aucun commentaire:

Enregistrer un commentaire