PDA

View Full Version : Load form panel fields from Json



qt4x11
15 Mar 2012, 12:59 PM
I have a form panel that loads field data from a Json servlet. When I click my 'Load' button, I get the wait message but my fields are not populated. I think maybe my reader or model is not working correctly. There aren't any errors in the console. I've also confirmed that my servlet is returning Json data.

My panel is



Ext.define('Ext.company.EditCompanyForm', {
extend : 'Ext.form.Panel',
frame : true,
bodyPadding : '10 10 10 100',
waitMsgTarget : true,
alias : 'widget.company-EditCompanyForm',
title : 'Edit Company',
fieldDefaults : {
labelAlign : 'left',
labelWidth : 85,
msgTarget : 'side'
},
// The fields
defaultType: 'textfield',
items : [ {
fieldLabel : 'Company Name',
name : 'companyName',
allowBlank : false
}, {
fieldLabel : 'Images URL',
name : 'defaultImageURL',
allowBlank : false
} ],
reader: {
type : 'json',
model: 'Ext.company.EditCompanyModel'
},
initComponent : function() {
this.buttons = [ {
text : 'Load',
handler : function() {
this.up('form').getForm().load({
url : '/servlet/CompanyServlet?action=getCompany',
waitMsg : 'Loading...'
});
}
}





and my model looks like


Ext.define('Ext.company.EditCompanyModel', {
extend : 'Ext.data.Model',
fields : [ {
name : 'companyID',
type : 'int'
}, {
name : 'companyName',
type : 'string'
}, {
name : 'defaultImageURL',
type : 'string'
} ]
});


-Not sure what I'm doing wrong. Any suggestions appreciated.

qt4x11
15 Mar 2012, 1:45 PM
Please ignore. I got it to work by structuring my Json like this page suggests

http://stackoverflow.com/questions/1351424/ext-js-formpanel-not-populating-fields-with-json-data