PDA

View Full Version : POST with remoteProxy and FormPanel doesn't work



sarah_iseli
18 Dec 2012, 6:09 AM
I've a mvc project and I'm trying to send the data from the FormPanel to a remote URL.

There we have a J2EE Backend. The specific method will be called, but the POST values are not sending.

In the controller I take the values from the form and add them to a store, load the store and do a sync:
rapportAddStore.setData(rapportValues);
rapportAddStore.load();

rapportAddStore.sync();

What must I do, to sent the POST values correctly?

Below is a extraction from the code:

Model:

Ext.define('mira.model.Rapport', {
extend: 'Ext.data.Model',
requires: [
'mira.model.Project',
'mira.model.ServiceType'
],
config: {
idProperty: 'id',
fields: [
{name: 'id', type: 'number'},
{name: 'commentExternal', type: 'string'},
{name: 'commentInternal', type: 'string'},
{name: 'date', type: 'date'},
{name: 'workTime', type: 'float'},
{name: 'travelTime', type: 'float'},
{name: 'isClearable', type: 'boolean'},
{name: 'state', type: 'string'},
{name: 'serviceTypeId', type: 'number'},
//{name: 'serviceTypeName', mapping: 'serviceType.name', type: 'string'},
{name: 'projectId', mapping: 'project.id', type: 'number'}
],
belongsTo: [{
model: 'mira.model.Project',
name: 'Project',
primaryKey: 'id',
foreignKey: 'projectId'
}],
hasOne: [{
model: 'mira.model.ServiceType',
name: 'ServiceType',
primaryKey: 'id',
foreignKey: 'serviceTypeId'
}],
}
});


Store:

Ext.define('mira.store.Rapports', {
extend: 'Ext.data.Store',


requires: [
'mira.model.Rapport',
'Ext.data.proxy.JsonP',
'Ext.data.proxy.Rest'
],

config: {
model: 'mira.model.Rapport',
sorter: 'date',
grouper: {
direction: 'DESC',
groupFn: function(record) {
return Ext.Date.format(record.get('date'), 'd. F Y');
}
},
// Create Proxy!!!
proxy: {
type: 'rest',
appendId: false,
api: {
create : 'https://....ch/ch.soreco.mira/rest/rapports/rapport',
read : 'https://....ch/ch.soreco.mira/rest/rapports/miraUser',
update : 'https://....ch/ch.soreco.mira/rest/rapports/rapport',
destroy: 'https://....ch/ch.soreco.mira/rest/rapports/rapport'
},
actionMethods: {
create: 'POST',
read: 'GET',
update: 'POST',
destroy: 'DELETE'
},
extraParams: {
format: 'js',
username: 'blatn2'
}
}
}


});

View:

Ext.define('mira.view.RapportAdd', {
extend: 'Ext.form.Panel',
xtype: 'rapportadd',
id: 'rapportForm',
requires: [
'Ext.Carousel',
'Ext.form.FieldSet',
'Ext.Label',
'Ext.form.Panel',
'mira.view.TimePicker',
'mira.view.AutocompleteField',
'mira.view.HourlyRateSelect',
'mira.view.ProjectSelect',
'Ext.field.Toggle',
'mira.view.ServiceTypeSelect',
'mira.view.TimePickerText'
],
config: {
// if the layout vbox and the flex = 1 from carousel
// isn't set the carousel didn't appear
layout: 'vbox',

items: [{
xtype : 'carousel',
flex: 1,


xtype:'carousel',
items: [{
// firstPage --> Projekt
items: {
xtype: 'fieldset',
items: [{
//TODO: add same css as label from textfield!!
xtype: 'label',
html: addRapport.firstPage.CUSTOMER
},
{
xtype: 'autocompletefield',
//name: 'customerId',
value: '',
// Label wirkt nicht zusammen mit config!
/*label: 'Das ist ein Label',
labelAlign: 'top',*/
config: {
//store: mira.store.CustomersSelectedByUser,
proxy: {
type: 'jsonp',
url: 'https://....ch/ch.soreco.mira/rest/customers/miraUserCustomer?username=isels3',
},
resultsHeight: 300,
needleKey: 'name',
labelKey: 'enterprise'
}
},
{
xtype: 'projectselect',
name: 'projectId',
label: addRapport.firstPage.PROJECT,
labelAlign: 'top'
},
{
xtype: 'hourlyrateselect',
name: 'hourlyRateId',
label: addRapport.firstPage.HOURLYRATE,
labelAlign: 'top'
}]
}
},
{
// secondPage --> Zeit
items: {
xtype: 'fieldset',
items: [
{
xtype: 'textfield',
name: 'worktime',
label: addRapport.secondPage.WORKTIME,
labelAlign: 'top'
},
{
xtype: 'textfield',
name: 'traveltime',
label: addRapport.secondPage.TRAVELTIME,
labelAlign: 'top',
},
{
xtype: 'datepickerfield',
label: addRapport.secondPage.DATE,
labelAlign: 'top',
name: 'date',
value: new Date(),
dateFormat: 'd.m.Y',
picker: {
//slotOrder: ['day', 'month', 'year'],
yearFrom: parseInt(Ext.Date.format(new Date(), 'Y'), 10)-1,
yearTo: parseInt(Ext.Date.format(new Date(), 'Y'), 10)+1
}
}
]
}
},
{
// thirdPage --> Art
items: {
xtype: 'fieldset',
items: [{
xtype: 'togglefield',
name: 'clearable',
label: addRapport.thirdPage.CLEARABLE,
labelAlign: 'top',
value: 1
},
{
xtype: 'servicetypeselect',
name: 'servicetypeId',
label: addRapport.thirdPage.SERVICETYPE,
labelAlign: 'top'
}]
}
},
{
// forthPage --> Kommentar
items: {
xtype: 'fieldset',
items: [{
xtype: 'textareafield',
maxRows: 4,
name: 'commentExternal',
label: addRapport.forthPage.COMMENTEXTERN,
labelAlign: 'top',
},
{
xtype: 'textfield',
name: 'commentInternal',
label: addRapport.forthPage.COMMENTINTERN,
labelAlign: 'top',
},
{
xtype: 'button',
ui: 'confirm',
text: buttons.SAVE,
action: 'submitRapportAdd'
}]
}
}]
}]
}
}
);

Controller:


Ext.define('mira.controller.RapportAdd', {
extend: 'Ext.app.Controller',
config: {
refs: {
rapportForm: '#rapportForm',
projectSelect: '#projecthallo',

},
views: ['RapportAdd', 'AutocompleteField', 'ProjectSelect', 'HourlyRateSelect']
},




init: function() {
this.control({
'button[action=submitRapportAdd]': {
tap: 'submitRapportForm'
},
//enterpriseTxt: {
// this will be handel in AutocompleteField
//},
projectSelect: {
change: 'changeProject'
}
});
},

submitRapportForm: function() {
var form = this.getRapportForm();
var rapportValues = form.getValues();

var rapportAddStore = Ext.create("mira.store.Rapports");
rapportAddStore.setData(rapportValues);
rapportAddStore.load();

rapportAddStore.sync();
}

});

ingo.hefti
20 Dec 2012, 5:59 AM
Did you make any progress on this? Just wondering because I remember once trying to do the same. Finally did my form posts with a simple ajax request...

sarah_iseli
2 Jan 2013, 11:06 PM
Unfortunately I couldn't do it the mentioned way. At the end I send the form as well with post directly to the url.