PDA

View Full Version : Jsonstore and exception



sashdce
9 Sep 2009, 11:27 PM
I am using a simple JsonStore , which calls a struts action class upon loading. The problem is that always an exception is throw ( caught by the listener exception). The response type is "Response" and the status code of the response is 200.
The store is -



var docPanelStore = new Ext.data.JsonStore({
proxy: new Ext.data.HttpProxy({url: 'docSelectAction.do'}),
root : 'root'
});
docPanelStore.on('exception', function(dp, type, action, options, response){

if


(type == 'remote') {

// A valid response was returned from the server having successProperty === false

Ext.MessageBox.alert('Error Message', response);
}
else if





(type == 'response') {

// An invalid response from the server was returned: either 404,

// 500 or the response meta-data does not match that defined
// in the DataReader (eg: root, idProperty, successProperty).
Ext.MessageBox.alert('Error Message',
"Status: " + response.status +
", Status Text: " + Ext.util.JSON.encode(response.responseText));
}





}




);






The json outputted is -


{"root":
[{"subGroups":
[{"subGroups":null,"docKeysList":null,"groupName":"Progress Notes","class":"edu.model.DocumentTypeGroup"},{"subGroups":null,"docKeysList":null,"groupName":"H&Ps","class":"edu.model.DocumentTypeGroup"},{"subGroups":null,"docKeysList":null,"groupName":"Consults","class":"edu.model.DocumentTypeGroup"},{"subGroups":null,"docKeysList":null,"groupName":"Operative Reports/Procedures/Post-op Notes","class":"edu.model.DocumentTypeGroup"}],
"docKeysList":null,
"groupName":"Physician Notes","class":"edu.model.DocumentTypeGroup"}]}}



please help on this. I am new to ext js.


~Sash

BitPoet
10 Sep 2009, 3:25 AM
You've got a superfluous closing curly bracket at the end of your json string. You can easily test your json data for correctness at http://www.jsonlint.com/.

sashdce
10 Sep 2009, 9:08 AM
Please ignore that. That got copied from the logs. The Json is well formed. What I understand is its mandatory to give the 'records' to the JsonStore constructor. Can some one help define the records field for this nested json. Here is the updated one -



{
"root": [
{
"subGroups": [
{
"subGroups": null,
"docKeysList": null,
"groupName": "Progress Notes",
"class": "edu.model.DocumentTypeGroup"
},
{
"subGroups": null,
"docKeysList": null,
"groupName": "H&Ps",
"class": "edu.model.DocumentTypeGroup"
},
{
"subGroups": null,
"docKeysList": null,
"groupName": "Consults",
"class": "edu.model.DocumentTypeGroup"
},
{
"subGroups": null,
"docKeysList": null,
"groupName": "Operative Reports/Procedures/Post-op Notes",
"class": "edu.model.DocumentTypeGroup"
}
],
"docKeysList": null,
"groupName": "Physician Notes",
"class": "edu.model.DocumentTypeGroup"
}
]
}

Condor
11 Sep 2009, 7:27 AM
It depends. Which fields do you want in your record?

sashdce
11 Sep 2009, 8:47 AM
I want to get all the fields except ofcourse the class. Plese guide.

Condor
11 Sep 2009, 9:43 AM
I mean this is 2 level data and a store can only read 1 level. Do you want the first lever or the second one?

sashdce
11 Sep 2009, 9:46 AM
Condor, I can get a handle to the first level by directly mapping it in the fields. The worry is how to get the second level. I want to do it at runtime, basically once the data loads, I am calling a callback which will interpret these results and form some html elements for me.

BitPoet
15 Sep 2009, 1:02 AM
In that case, I'd probably use a normal Ext.Ajax.request instead of a full fledged store, use Ext.decode on the return data, recurse over it and call Ext.XTemplate.apply for each level.