PDA

View Full Version : Complex json object into a GridPanel



MmarcoM
24 Aug 2009, 7:33 AM
Hello all,
i have the following java object which i am serlializing to Json

class Queue
{
QueueId id;
Date changeDate;
String changeUser;
String comments;
QueueItemState queueItemState;
....
}

class QueueId
{
private String id;
private int version;
}

here's the json rendered (which looks perfect, ihave checked it thru JLint)

{"model":
{"queueStates":
[{"id": {"id": "Id0","queueStateVersion": "0"},"changeDate": "Mon Aug 24 16:22:10 BST 2009","changeUser": "USER0","comments": "COMMENT0","queueItemState": "PENDING"},
{"id": {"id": "Id1","queueStateVersion": "1"},"changeDate": "Mon Aug 24 16:22:10 BST 2009","changeUser": "USER1","comments": "COMMENT1","queueItemState": "PENDING"}]
}
}
here's my simple Grid

Ext.onReady(function(){


var pendingStore = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url: '../queue.htm'}),
reader: new Ext.data.JsonReader({
root:'model.queueStates'

}, [{name: 'id', mapping:'id.id'},
{name: 'state' , mapping:'state'},
{name: 'username' , mapping:'username'},
{name: 'comment' , mapping:'comment'}])
});

pendingStore.load();


// create the grid
var pendingGrid = new Ext.grid.GridPanel({
id: 'pendingGrid',
title:'Pending',
store: pendingStore,
columns: [
{header: "Id", width: 100, dataIndex:'id', sortable:true},
{header: "State", width: 180, dataIndex: 'state', sortable: true},
{header: "Timestamp", width: 180, dataIndex: 'timestamp', sortable: true},
{header: "Username", width: 115, dataIndex: 'username', sortable: true},
{header: "Comment", width: 100, dataIndex: 'comments', sortable: true}
],
width:540,
height:200,
listeners: {
activate: function() {
loadPendingStore();
}
}
});


function loadPendingStore()
{
alert('loadign pending store..');
pendingStore.load();
}

});

When the list appear, it shows just one record.

if i omit the QueueId frojm the json object (by creating Queue objects with null QueueId),e verything works fine...
i was guessing that maybe Json was incorrect, but given that JSLint says that teh JsonString is a valid one then i m start to think that mayb my ext grid code is incorrect...

anyone could help?

thanks and regards
marco