PDA

View Full Version : form load() always return failure



Alexei Ptitchkin
3 Aug 2012, 6:06 AM
I have very strange Ext.form.Panel misbehavior. Form load() always return failure regardless that POST request sent and processed by servlet.

Servlet response for load is:

{"success":true,
"data":{
"userGrpId":2,
"userCode":"Q03451",
"userName":"E Gu",
"status":"Active",
"userGroup":{"groupName":"Admin",
"groupDesc":"Company Admin",
"updateOn":"09/19/2011 12:38:09",
"updateBy":"George Zhang",
"id":2,"idx":0},
"isAPApprover":true,
"isPrdApprover":true,
"isSalesRep":false,
"isSalesManager":false,
"isFctApprover":true,
"isPrdBypass":true,
"isAPBypass":false,
"isFctBypass":true,
"isPrdEmailExempt":false,
"isAPEmailExempt":false,
"isFctEmailExempt":true,
"createOn":"08/03/2012 09:21:32",
"createBy":"E Gu",
"updateOn":"01/31/2012 17:26:53",
"updateBy":"Scott W",
"id":71,"idx":0}}"

Model used in form and store:

Ext.define('Fast.model.company.UserDetailModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'id'},
{name: 'userCode', type: 'string'},
{name: 'userName', type: 'string'},
{name: 'userCodeDis', mapping:"userCode"},
{name: 'userNameDis', mapping:"userName"},
{name: 'accessLevel', type: 'string', mapping:"userGroup.groupName"},
{name: 'status', type: 'string'},
{name: 'prodApprover', type: 'boolean',mapping:'isPrdApprover'},
{name: 'fcastApprover', type: 'boolean', mapping:'isFctApprover'},
{name: 'salesPerson', type: 'boolean', mapping:'isSalesRep'},
{name: 'accountApprover', type: 'boolean', mapping:'isAPApprover'},
{name: 'salesManager', type: 'boolean',mapping:'isSalesManager'},
{name: 'prdBypass', type: 'boolean', mapping:'isPrdBypass'},
{name: 'apBypass', type: 'boolean', mapping:"isAPBypass"},
{name: 'fctBypass', type: 'boolean',mapping:'isFctBypass'},
{name: 'prdEmailExempt', type: 'boolean', mapping:'isPrdEmailExempt'},
{name: 'apEmailExempt', type: 'boolean', mapping:'isAPEmailExempt'},
{name: 'fctEmailExempt', type: 'boolean',mapping:'isFctEmailExempt'},
{name: 'userGrpId'}
]
});


Form declaration code:

Ext.define('Fast.view.company.CompanyUserDetailForm' ,{
extend : 'Ext.form.Panel',
alias : 'widget.CompanyUserDetailForm',
// configure how to read the json data
reader : new Ext.data.JsonReader({
root : 'data',
model : 'UserDetailModel'
}),
items : [ ... ],
dockedItems: [{
xtype: 'toolbar',
dock: 'top',
layout: {pack: 'left'},
items: [{ minWidth: 80,
text: 'Save',
iconCls: 'icon-save',
id:"saveBtn",
action:'userDetailEditSave'
}]
}]
});

Form load code:

editUserDetail : function(button) {
var gridPanel = this.getCompanyUserSelectGrid();
var selectedRecord = gridPanel.getSelectionModel().getSelection()[0];
var url='json/companyUserDetailsAction?m=read';
selectUserId= selectedRecord.get('userCode');
selectUserName= selectedRecord.get('userName');
status= selectedRecord.get('status');
var userDetailForm = this.getCompanyUserDetailForm();
userDetailForm.getForm().load({ url: 'json/companyUserDetailsAction?m=read'
,params :{pram1:selectUserId, pram2:selectUserName,pram3:status}
,failure: function(form, action){
var failureType = action.failureType;
var response = action.response;
var result = action.result;
var type = action.type;

Ext.MessageBox.show({title: 'userDetailForm load fail',
msg: "failureType = "+ failureType+"\n response = "+response +"\nresult = "+result +"\ntype = "+type,
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK});
}
,success: function(form, action){
alert('userDetailForm load succeed');
var cardPanel = gridPanel.up('panel');
var cardLayout = cardPanel.getLayout();
cardLayout.setActiveItem(1);
}
//,waitMsg: 'Loading User Details...'
});

}


Values in action par-r sent to failure:

failureType = load
response = full server response (see above)
result = Object {success:false, data:null}
type = load

Could you please explain what I'm doing wrong.
Thank you.

joaquingt
3 Aug 2012, 7:04 AM
you have an extra " at the end of your json
are you using firebug to check the json response ?

Alexei Ptitchkin
3 Aug 2012, 7:29 AM
Yes I use firebug, for some reason I copied response from debugger window and grab extra quote.

Here is response taken from firebug console



{"success":true, "data":{"userGrpId":2,"userCode":"Q03451","userName":"Eric Gu","status":"Active","userGroup":{"groupName":"Admin","groupDesc":"Company Admin","updateOn":"09/19/2011 12:38:09","updateBy":"George Zhang","id":2,"idx":0},"isAPApprover":true,"isPrdApprover":true,"isSalesRep":false,"isSalesManager":false,"isFctApprover":false,"isPrdBypass":true,"isAPBypass":false,"isFctBypass":false,"isPrdEmailExempt":false,"isAPEmailExempt":false,"isFctEmailExempt":false,"createOn":"08/03/2012 10:10:02","createBy":"Eric Gu","updateOn":"01/31/2012 17:26:53","updateBy":"Scott Webber","id":71,"idx":0}}

scottmartin
3 Aug 2012, 7:44 AM
Try hard coding successProperty: 'success' set in your reader.

Can you load the provided JSON from a file correctly?

Scott.

Alexei Ptitchkin
3 Aug 2012, 7:49 AM
I thought 'success' is default value for successProperty (I have tried this).
I use the same model in grid, model accept array of same jsons without any problem.

scottmartin
3 Aug 2012, 9:12 AM
To simplify this, I created the following and it loads fine and success is returned:



Ext.define('UserDetailModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'id'},
{name: 'userCode', type: 'string'},
{name: 'userName', type: 'string'},
{name: 'userCodeDis', mapping:"userCode"},
{name: 'userNameDis', mapping:"userName"},
{name: 'accessLevel', type: 'string', mapping:"userGroup.groupName"},
{name: 'status', type: 'string'},
{name: 'prodApprover', type: 'boolean',mapping:'isPrdApprover'},
{name: 'fcastApprover', type: 'boolean', mapping:'isFctApprover'},
{name: 'salesPerson', type: 'boolean', mapping:'isSalesRep'},
{name: 'accountApprover', type: 'boolean', mapping:'isAPApprover'},
{name: 'salesManager', type: 'boolean',mapping:'isSalesManager'},
{name: 'prdBypass', type: 'boolean', mapping:'isPrdBypass'},
{name: 'apBypass', type: 'boolean', mapping:"isAPBypass"},
{name: 'fctBypass', type: 'boolean',mapping:'isFctBypass'},
{name: 'prdEmailExempt', type: 'boolean', mapping:'isPrdEmailExempt'},
{name: 'apEmailExempt', type: 'boolean', mapping:'isAPEmailExempt'},
{name: 'fctEmailExempt', type: 'boolean',mapping:'isFctEmailExempt'},
{name: 'userGrpId'}
],
proxy:
{
type: 'ajax',
url: 'data.json',
autoLoad: false,
pageSize: 25,

reader: {
type: 'json',
root: 'data',
successProperty: 'success'
}
}

});

store = new Ext.data.Store({
autoLoad: true, // need to have users available for combos in other apps
type: 'json',
model: 'UserDetailModel',
});




Ext.onReady(function(){

var form = Ext.create('Ext.form.Panel', {
title: 'Simple Form',
bodyPadding: 5,
width: 350,

// Fields will be arranged vertically, stretched to full width
layout: 'anchor',
defaults: {
anchor: '100%'
},

// The fields
defaultType: 'textfield',
items: [{
fieldLabel: 'userCode',
name: 'userCode'
},{
fieldLabel: 'userName',
name: 'userName'
}],

renderTo: Ext.getBody()
});

Ext.create('Ext.Button', {
text: 'Load Store',
renderTo: Ext.getBody(),
handler: function() {
store.load();
console.log(store.getCount());
}
});

Ext.create('Ext.Button', {
text: 'Load Form',
renderTo: Ext.getBody(),
handler: function() {
form.load({
url: 'data.json',
success: function(){
console.log('success');
}
});
}
});

});


Scott.

caiocosta
3 Oct 2012, 9:40 AM
I've the same problem.... return only "{success: true}" and form fail!

39112