PDA

View Full Version : some data.Field are not posted when I modifie a record



flamant
9 Mar 2011, 4:02 AM
Hi,
I have a Jsonstore with Ext.data.Field as following :



gridFields[j] = new Ext.data.Field({
name: field.fldId,
mapping: field.fldId,
atLeastOneYes: field.atLeastOneYes

});
j++;
gridFields[j] = new Ext.data.Field({
name: field.fldId + '_STAT',
mapping: field.fldId + '_STAT',
defaultValue: '999'


});
j++;
gridFields[j] = new Ext.data.Field({
name: field.fldId + '_FCB',
mapping: field.fldId + '_FCB',
defaultValue: ''
});
j++;
and the jsonStore :
var remoteGridJsonStore = new Ext.data.JsonStore({
proxy: remoteGridProxy,
baseParams: baseParams,
storeId: 'remoteGridJsonStore_' + sptNbr + '_' + gridNbr,
root: 'records',
autoLoad: false,
totalProperty: 'totalCount',
remoteSort: false,
fields: gridFields,
idProperty: 'id',
autoSave: false,


Furthermore in some cases I create a record when the jsonStore is empty this way :



var newRecord = new remoteGridJsonStore.recordType({
newRecordId : Ext.id()
});
newRecord.set('rowSeq', rowSeq);
newRecord.set('markToDelete', false);
newRecord.set('mark', false);
newRecord.set(........)

remoteGridJsonStore.add(newRecord);


When I change the values of the record and I post the jsonStore some Ext.data.Field of my record are not posted. I checked that all the values are present in the record and the store but some are not posted

I don't know how to solve this. Everything seems to be correct

Thank you in advance for your answers

mitchellsimoens
9 Mar 2011, 7:09 AM
What do you mean post the JsonStore? You mean submit the modified records?

If you are using a Writer on the Store, by default it will only submit the modified fields. To change this, on your Writer, set the config property writeAllFields to true.

http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.DataWriter

flamant
9 Mar 2011, 7:32 AM
Hi mitchellsimoens and thank you for your answer,
yes I mean submit the modified records

actually I already use as you said a Writer with the writeAllFields property set to true. But some of my data.fields are not submitted

mitchellsimoens
9 Mar 2011, 7:34 AM
And you have made sure that your records have the fields you want?

It's kind of hard to visualize what you are doing as it seems you have copied and pasted some code together so it's messy code that you posted.

flamant
9 Mar 2011, 8:07 AM
Sorry, here is the entire code :
The Ext.data.Field


gridFields[0] = new Ext.data.Field({
name: 'id',
mapping: 'id'
});
gridFields[1] = new Ext.data.Field({
name: 'rowSeq',
mapping: 'rowSeq',
type: 'int'
});
gridFields[2] = new Ext.data.Field({
name: 'markToDelete',
mapping: 'markToDelete',
type: 'boolean'
});
gridFields[3] = new Ext.data.Field({
name: 'mark',
mapping: 'mark',
type: 'boolean'
});
gridFields[4] = new Ext.data.Field({
name: 'unmark',
mapping: 'unmark',
type: 'boolean'
});
var j = 5;
for (var i = 0; i < pageGridFields.records.length; i++) {
field = pageGridFields.records[i];
if (field.fldType == "SLE"
|| field.fldType == "MLE"
|| field.fldType == "NUM"
|| field.fldType == "DAT"
|| field.fldType == "CBX"
|| field.fldType == "SLB"
|| field.fldType == "DLB") {
gridFields[j] = new Ext.data.Field({
name: field.fldId,
mapping: field.fldId,
atLeastOneYes: field.atLeastOneYes

});
j++;
gridFields[j] = new Ext.data.Field({
name: field.fldId + '_STAT',
mapping: field.fldId + '_STAT',
defaultValue: '999'


});
j++;
gridFields[j] = new Ext.data.Field({
name: field.fldId + '_FCB',
mapping: field.fldId + '_FCB',
defaultValue: ''
});
j++;
}
}


}


The store with its proxy and writer :


var gridWriter = new Ext.data.JsonWriter({
writeAllFields: true
});
var remoteGridProxy = new Ext.data.HttpProxy({
api:{
read: { url: '../secure/getSubjectDataGrid.htm', method: 'GET', timeout: 240000 },
create: { url: '../secure/createSubjectDataGrid.htm', method: 'POST', timeout: 240000 },
update: { url: '../secure/updateSubjectDataGrid.htm', method: 'POST', timeout: 240000 },
destroy: { url: '../secure/deleteSubjectDataGrid.htm', method: 'POST', timeout: 240000 }
}
});
var remoteGridJsonStore = new Ext.data.JsonStore({
proxy: remoteGridProxy,
baseParams: baseParams,
storeId: 'remoteGridJsonStore_' + sptNbr + '_' + gridNbr,
root: 'records',
autoLoad: false,
totalProperty: 'totalCount',
remoteSort: false,
fields: gridFields,
idProperty: 'id',
autoSave: false,
successProperty: 'success',
writer: gridWriter,
.................................


The creation of the new record which is not entirely submited :


var newRecord = new remoteGridJsonStore.recordType({
newRecordId : Ext.id()
});
newRecord.set('rowSeq', rowSeq);
newRecord.set('markToDelete', false);
newRecord.set('mark', false);
remoteGridJsonStore.add(newRecord);
recordId = newRecord.id;

for (var k = 0; k < pageGridFields.records.length; k++) {
field = pageGridFields.records[k];
if (field.fldType == "CBX") {
newRecord.set(field.fldId, false);
} else {
newRecord.set(field.fldId, '');
}
newRecord.set(field.fldId + '_STAT', '999');
newRecord.set(field.fldId + '_FCB', '');
formFields[k] = buildField(field, recordId, rowSeq, remoteGridJsonStore, subjectId, frozen, screenSequence, id, sptNbr, gridNbr);
addDefaultValue(formFields[k]);
if (isEditField(field)) {
newRecord.set(field.fldId, formFields[k].getValue());
}
}


Actually some '_STAT' Ext.data.Field are not submitted

I change the value of those '_STAT' Ext.data.Field in the change handler of Ext.form.Field



listeners: {
change: function(field, newValue, oldValue) {
var record = field.jsonStore.getById(field.rowId);
record.set(field.fieldId, field.getRawValue());
var oldStatus = record.get(field.fieldId+'_STAT');
if (oldStatus == Status.NEVENT && newValue != '') {
record.set(field.fieldId+'_STAT', Status.NOTCLE_NEVMAR_COM);
}
},

mitchellsimoens
9 Mar 2011, 8:13 AM
One thing I see is when you create a new record, you do this:


var newRecord = new remoteGridJsonStore.recordType({
newRecordId : Ext.id()
});
newRecord.set('rowSeq', rowSeq);
newRecord.set('markToDelete', false);
newRecord.set('mark', false);
remoteGridJsonStore.add(newRecord);
recordId = newRecord.id;

According to the API docs, to create a new record, you should do this:


var id = Ext.id();
var newRecord = new remoteGridJsonStore.recordType({
newRecordId : id,
rowSeq : rowSeq,
markToDelete : false,
mark : false
}, id);
remoteGridJsonStore.add(newRecord);
recordId = id;

First param should be a data object and the second should be an id (which is optional)

flamant
9 Mar 2011, 8:14 AM
I also try to debug with ext-all-debug.js but I don't know where I can put a breakpoint to see which data.Fields are submited

mitchellsimoens
9 Mar 2011, 8:23 AM
I also try to debug with ext-all-debug.js but I don't know where I can put a breakpoint to see which data.Fields are submited

If you are using Firebug or WebKit Inspector, you can see the request and response.

flamant
9 Mar 2011, 8:32 AM
var id = Ext.id();
var newRecord = new remoteGridJsonStore.recordType({
newRecordId : id,
rowSeq : rowSeq,
markToDelete : false,
mark : false
}, id);
remoteGridJsonStore.add(newRecord);
recordId = id;


I also already tried this former way but without success

flamant
10 Mar 2011, 10:18 AM
I finally solved the problem,
In fact the fields in the record that were not sent had a "undefined" value and EXTJS doesn't send them