PDA

View Full Version : Problem JSONReader <=> XMLReader



olivierpons
16 Feb 2011, 8:40 AM
Hi!
I tried to make my component descending from FormPanel, then copy- paste the code from the example, and on the server side, return XML :


DossierPanel = Ext.extend(Ext.form.FormPanel, {
closable: true,
autoScroll:true,
initComponent : function(){
this.title = 'test';

// configure how to read the XML Data
this.reader = new Ext.data.XmlReader({
record : 'contact',
success: '@success'
}, [
{name: 'first', mapping:'name/first'}, // custom mapping
{name: 'last', mapping:'name/last'},
'company', 'email', 'state',
{name: 'dob', type:'date', dateFormat:'m/d/Y'} // custom data types
]);
this.items= [
new Ext.form.FieldSet({
title: 'Contact Information',
autoHeight: true,
defaultType: 'textfield',
items: [{
fieldLabel: 'First Name',
emptyText: 'First Name',
name: 'first',
width:190
}, {
fieldLabel: 'Last Name',
emptyText: 'Last Name',
name: 'last',
width:190
}, {
fieldLabel: 'Company',
name: 'company',
width:190
}, {
fieldLabel: 'Email',
name: 'email',
vtype:'email',
width:190
},

new Ext.form.DateField({
fieldLabel: 'Date of Birth',
name: 'dob',
width:190,
allowBlank:false
})
]
})
];
DossierPanel.superclass.initComponent.call(this);
}
});


And here's the data that is returned from the server:


<?xml version="1.0" encoding="UTF-7"?>
<message success="true">
<contact>
<name>
<first>Jack</first>
<last>Slocum</last>
</name>
<company>Ext JS</company>
<email>[email protected]</email>
<state>OH</state>
<dob>04/15/2007</dob>
</contact>
</message>

This doesn't work because it thinks it's JSON and tries to evaluate it.
This would mean (maybe I'm wrong) that the reader is not taken in account. It's ignored.
How shall I do to make it work?

Any idea? I've been stuck for one day now...

To be more precise, the error I get is :

and the code error is in ext-all-debug:
in the object

Ext.util.JSON = new (function(){
...blabla...
return eval("(" + json + ")");

That's why I guess it's not treated as XML but as JSON. Thus... I guess the reader declaration is ignored. Any idea?

Thank you very much.