To handle success or fail store.sync() I use to pass sync options with callbacks.
Code:
var syncOptions = {controller:this,
record:record,
recordId:recordId,
dealerStore:dealerStore,
wnd:wnd,
success:this.lookupDealerSyncCallback,
failure:this.failureSyncCallback};
this.getDealersLookupStore().sync(syncOptions);
On server side I always write json response to client using:
Code:
this.getResponse().setContentType("application/json;charset=UTF-8");
this.getResponse().getWriter().write(json);
then if sync() succeed within call back I can access response text via batch.operations[0].response.responseText
Code:
lookupDealerSyncCallback:function (batch, syncOptions){
syncOptions.dealerStore.load();
syncOptions.wnd.close();
//batch.operations[0].response.responseText = "{"dealers":
// {"dealerCode":"BSDA","dealerName":"BUSINESS SOLUTIONS DIVISION,",
// "hasDefaultAllocation":"N","hasForecast":"Y","hasSellHand":"N",
// "hasQuota":"Y","createOn":"08/22/2012 13:29:09","createBy":"Eric Gu",
// "updateOn":"08/22/2012 13:29:09","updateBy":"Eric Gu",
// "ordinal":0,"id":283,"idx":0},"success": true }"
var responseObj = Ext.JSON.decode(batch.operations[0].response.responseText,true);
var newDealerId = responseObj.dealers.id;
syncOptions.record.setId(newDealerId);
syncOptions.controller.openDealerDetailWnd(null, syncOptions.record);
},
but if sync() fail batch.operations[0] does not have 'response' property and I don't have any message to show.
Code:
failureSyncCallback:function (batch, syncOptions){
syncOptions.dealerStore.load();
/*
* here batch.operations[0] does not have 'response' property
*/
},
How I can get error message in failure callback?
Thank you.