Question

Im trying to impelement comunication between ExtJS and Java I'm sending requests from ExtJS to a Java server thats using netty. I would appriciate if someone could send me an example of how the response should be formated from the java side and how to read the response data from the ExtJS side thanks in advance. This is my source from the ExtJS side

var store = new Ext.data.JsonStore({
    autoload: true,
    baseParams: {
        conid : '6b09477f-aa04-4f5a-b969-05277d01f07e'
    },
    root: 'OpenCashTime',
    proxy: new Ext.data.ScriptTagProxy({
        url: 'http://localhost:8080/getOpenCash?'
    }),
    fields: [{name: 'Time', mapping: 'Time', type: 'int'}]                  
});
store.load();
store.on('load', function() {
    alert(store.getTotalCount());                   
});
store.on('write', function() {                  
    alert(store.getTotalCount());
});
store.on('loadexception', function() {
    alert("AAAAAA");
});
store.on('metachange', function() {
    //alert(store.getTotalCount());
});
store.on('update', function() {
    //alert(store.getTotalCount());
});
store.on('save', function() {
    //alert(store.getTotalCount());
});
store.on('datachanged', function() {
    //alert(store.getTotalCount());
});

When executing this code and reciving this response {"OpenCashTime":[{"Time":1291623637000},{"Time":1294914317000}]} I still get a loadexception although even firebug sees its Json

Was it helpful?

Solution

Assuming from your title, that you want to load data into JsonStore, it expects a valid Json string, with a property storing an array of JSON objects, that will be loaded as records. The property name is set up by root property when configuring JsonStore.

Store like this:

{
  xtype: 'jsonstore',
  root: 'data',
  idProperty: 'ID',
  fields: [
    {name: 'ID', mapping: 'ID', type: 'int'}
    {name: 'someDate', mapping: 'someDate', type: 'date', dateFormat: 'Y-m-d'}
  ],
  url: 'hereBeYourURl'
}

Will gladly eat something like this:

{"data":[{"ID":"1","someDate":"2002-10-02"},{"ID":"2","someDate":"2002-05-22"}]}

OTHER TIPS

fields: [{name: 'Time', mapping: 'Time', type: 'int'}]  
fields: [{name: 'Time', type: 'int'}]  

BTW In the case of an identity mapping you can leave it out. These two cases will give you the same results.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top