PDA

View Full Version : Strange results using json-lib



rindress
27 Jul 2007, 10:29 AM
I am trying to populate a Grid control. I've setup the following Ext.data.Store


var Users = Ext.data.Record.create([ {
name: 'login_name',
mapping: 'login_name'
}, {
name: 'last_name',
mapping: 'last_name'
}, {
name: 'created_at',
mapping: 'created_at'
}, {
name: 'updated_at',
mapping: 'updated_at'
}, {
name: 'first_name',
mapping: 'first_name'
}, {
name: 'groups',
mapping: 'groups'
}]);

ds = new Ext.data.Store( {
reader: new Ext.data.JsonReader( {
root: 'Users',
totalProperty: 'Total'
}, Users)
});


After creating the column model I setup the grid using:


grid = new Ext.grid.Grid('users_grid', {
ds: ds,
cm: cm,
selModel: new Ext.grid.RowSelectionModel( {
singleSelect: true
}),
autoExpandColumn: 'login_name',
loadMask: true
});


Next is where I believe I deviate from most. I'm using JBoss seam and it's 'remote' capability to load the data for the grid. So I have a function that gets called in the onReady() handler.


var userDataFromServer;

function loadUserData() {
var action = Seam.Component.getInstance("list");
if( action != null )
{
action.getUserData( name, userDataLoaded);
}
}

function userDataLoaded(result) {
userDataFromServer = result;
ds.loadData( userDataFromServer, false);
}


When I set a breakpoint in Firebug at the ds.loadData line I can see that the result is not formated correct. I get back the following:



{"Users":[{"first_name":"zool","description":"asdfasdf","last_name":"bar","groups":"Admin,Users"}],"Total":"1"}


The server side code that generated this is:


public JSON getList4( String s ){
HashMap<String,String> rslts = new HashMap<String,String>();
rslts.put("Total", "1");
ArrayList<HashMap<String,String>> userEntries = new ArrayList<HashMap<String,String>>();
HashMap<String,String> userEntry = new HashMap<String,String>();
HashMap<String,Object> al2 = new HashMap<String,Object>();
userEntry.put("first_name", "zool");
userEntry.put("last_name","bar");
userEntry.put("description", "asdfasdf");
userEntry.put("groups", "Admin,Users");
userEntries.add(userEntry);
al2.put("Users", userEntries);
al2.put("Total", "1");
System.out.println(" user stuff = " + JSONSerializer.toJSON(al2));

return JSONSerializer.toJSON(al2);
}


I must be missing something here.

Any pointers? Is there further information required?

Thanks in advance,
Rindress