PDA

View Full Version : struggling to load xml data in form



raphinou
4 May 2007, 12:32 AM
Hi,

I'm using the yui-adapter, trying to load xml data in a form. I'm following the example at http://extjs.com/deploy/ext/examples/form/xml-form.html .

The request is sent to the server and the xml is retrieved, but the form fields aren't filled. I'm first defining a UserRecord, with all fields in the xml being mapped. I then define a XmlReader, which reads UserRecords. And I use this reader in the form. I've removed baseParams as I read this could be problematic (http://extjs.com/forum/showthread.php?t=5032&highlight=Form+load).

But the form fields don't get filled, and I don't get any error in firebug.

I put the code below in the hope someone can help me as I don't see what I'm doing wrong. thanks in advance.



UserRecord = Ext.data.Record.create([
{ name: 'id'},
{ name: 'name'},
{ name: 'firstname'},
{ name: 'birthday', type:'date', format: 'Y-m-d'},
{ name: 'street'},
{ name: 'zip_code', mapping: "zip-code"},
{ name: 'city'},
{ name: 'email'},
{ name: 'login'},
{ name: 'identity_url', mapping: "identity-url"},
{ name: 'country'}
]);

user_reader= new Ext.data.XmlReader({
record: 'user',
id: 'id'
},
UserRecord
);

user_form = new Ext.form.Form({
labelWidth: 100,
url:'/user/9.xml',
method: 'get',
reader: user_reader

});

user_form.add(new Ext.form.TextField({
fieldLabel: "First name",
name: "firstname"
}));
user_form.add(new Ext.form.TextField({
fieldLabel: "Name",
name: "name"
}));
user_form.add(new Ext.form.DateField({
fieldLabel: "Birthday",
name: "birthday"
}));
user_form.add(new Ext.form.TextField({
fieldLabel: "Street",
name: "street"
}));
user_form.add(new Ext.form.TextField({
fieldLabel: "Zip code",
name: "zip_code"
}));
user_form.add(new Ext.form.TextField({
fieldLabel: "City",
name: "city"
}));
user_form.add(new Ext.form.TextField({
fieldLabel: "Country",
name: "country"
}));

user_form.render("user_form");
user_form.load( );


and the xml loaded is:
[code]
<?xml version="1.0" encoding="UTF-8"?>
<user>
<birthday type="date">1975-01-01</birthday>
<city>Brussels</city>
<country>Belgium</country>
<email>[email protected]</email>
<firstname>Rapha

tryanDLS
4 May 2007, 9:01 AM
Are you serving your xml with the right content-type - there are several threads regarding this. If you send it as plain text it won't get parsed. Set a BP in XmlReader.read and look at the response.

raphinou
5 May 2007, 9:24 AM
the content type was "application/xml", and I also tried with "text/xml" but with the same result. The charset is utf-8.

raph

raphinou
12 May 2007, 2:33 AM
In case anyone else gets the same problem, here the solution that solved it for me:

I needed to add



<response>
<success>true</success>
</response>


to the xml sent back by the server.