PDA

View Full Version : [STALE-462][3.1] XmlWriter render bug



maho2nd
21 Jan 2010, 12:37 AM
Ext version tested:


Ext 3.1.0

Adapter used:


ext

css used:


only default ext-all.css

Browser versions tested against:


FF3.5.7 (firebug 1.4.5 installed)

Operating System:


WinXP

Description:


If you call the render method in XMLWriter with no data(records), it renders an empty record in params.xmlData instead of no record



Test Case:

var params = {};
var baseParams = {};
var allRecords = [];
myStore.writer.apply(params, baseParams, 'update', allRecords); params.xmlData is:
<root>
<element></element>
</root>

instead of
<root>
</root>

Fix:



render : function(params, baseParams, data) {
baseParams = this.toArray(baseParams);
params.xmlData = this.tpl.applyTemplate({
version: this.xmlVersion,
encoding: this.xmlEncoding,
documentRoot: (baseParams.length > 0 || this.forceDocumentRoot === true) ? this.documentRoot : false,
record: this.meta.record,
root: this.root,
baseParams: baseParams,
// records: (Ext.isArray(data[0])) ? data : [data]
records: (Ext.isArray(data[0]) || data.length == 0) ? data : [data]
});
}
(last line changed)

dayext
28 Jan 2010, 5:55 AM
Shouldn't the isArray check be on data and not on its first element?


records: Ext.isArray(data) ? data : [data]

This way you don't need the length check, since empty arrays will be passed through as empty arrays.

(Note: not tested, pure theory)

evant
31 Jan 2010, 7:02 PM
Care to post a full test case? I can't replicate the behaviour:



Ext.onReady(function(){

var store = new Ext.data.Store({
reader: new Ext.data.XmlReader({
record: 'root'
}, [{
fields: 'f1'
}]),
writer: new Ext.data.XmlWriter()
});

var params = {};
var baseParams = {};
var allRecords = [];
store.writer.apply(params, baseParams, 'update', allRecords);
console.log(params);
});