PDA

View Full Version : JSONStore Creation for SDF Webservice



irscomp
24 Mar 2010, 6:24 AM
Hi All,

I am facing issue creating JSON Store for my Webservice result.

I am getting response back in JSON Format, but the object which is returning is in different format.

Please Help me out, how I can proceed.

In this URL

var jsonReq = {
"getProductSearchData": {
"DlpProductSearchFormRequest": {
"productName": {
"$": productSearchName
},
"countryCd": {
"$": Ext.ComponentMgr.get('shipToProductCountry').getValue()
},
"pageRec": {
"$": "10"
},
"pageNum": {
"$": "1"
}
}
}
};

var jsonReqObj = Ext.util.JSON.encode(jsonReq);

Ext.Ajax.request({
url: "/DlpApp/services/ProductService",
//url: "/DlpApp/content/jsp/sd.json",
method: 'POST',
headers: {
'Content-Type': 'application/json/badgerfish; charset=utf-8'
},
jsonData: jsonReqObj,

success: function(responseObject){
var dataObj = Ext.decode(responseObject.responseText);
if (dataObj.getProductSearchDataResponse.DlpProductSearchFormResponse.errorMessage.$ != undefined) {
alert('Error : ' + dataObj.getProductSearchDataResponse.DlpProductSearchFormResponse.errorMessage.$);
}
else {
dataObj = dataObj.getProductSearchDataResponse.DlpProductSearchFormResponse;
var productSearchGridStore = Ext.ComponentMgr.get('productSearchGrid').store;
var productSearchRecords = productSearchGridStore.recordType;
productSearchGridStore.removeAll();

if (dataObj.productList != undefined) {
if (dataObj.productList[0] != undefined) {
for (var i = 0; i < dataObj.productList.length; i++) {
var rec = new productSearchRecords();

rec.data.productName = dataObj.productList[i].productName.$;
rec.data.productDesc = dataObj.productList[i].productDesc.$;
rec.data.listPrice = dataObj.productList[i].listPrice.$;
rec.data.createdUpdatedDate = dataObj.productList[i].createdUpdatedDate.$;
rec.data.availableQty = dataObj.productList[i].availableQty.$;
rec.data.status = dataObj.productList[i].status.$;
rec.data.orderedQty = "";

productSearchGridStore.addSorted(rec);
}
}
else {
var rec = new productSearchRecords();

rec.data.productName = dataObj.productList.productName.$;
rec.data.productDesc = dataObj.productList.productDesc.$;
rec.data.listPrice = dataObj.productList.listPrice.$;
rec.data.createdUpdatedDate = dataObj.productList.createdUpdatedDate.$;
rec.data.availableQty = dataObj.productList.availableQty.$;
rec.data.status = dataObj.productList.status.$;
rec.data.orderedQty = "";

productSearchGridStore.addSorted(rec);

}
}
}
},
failure: function(responseObject){
alert("Error while getting Product Search.");
}
});


In the above code I am using JSON ArrayReader property. by which its working fine. But I wanted to Use Direct URL call in my store. :-? there I am getting issues.

I am not getting How i can set productId.$ value as dataIndex in my grid and how should I assign root property.

My Webservices code are in Apache Axis2 base.

Please help me out.

irscomp
25 Mar 2010, 10:11 PM
http://www.zunisoft.com/?p=65

This website gives the json reader which convert badgerfish json to normal one.

I have modified code for my need and its done.
..