PDA

View Full Version : Problem with Store and XmlWriter/Reader



jblb
2 Jan 2015, 7:18 AM
Hi Forum


I'm pretty new to ExtJS and I hope someone can help me.


I have a Record-Definition, an http-Proxy, a store with a xmlReader/Writer, a GridPanel and an Add-Button.



var EntryDef = Ext.data.Record.create([
'entryid', 'name' ]);

Ext.onReady(function(){


var httpProxy = new Ext.data.HttpProxy({
api: {
read: '/ibis/servlet/IBISHTTPUploadServlet/EPM-LFW.C.0002.http-GetDefaultValues',
create: '/ibis/servlet/IBISHTTPUploadServlet/EPM-LFW.C.0002.http-CreateDefaultValues',
update: '/ibis/servlet/IBISHTTPUploadServlet/EPM-LFW.C.0002.http-UpdateDefaultValues',
destroy: '/ibis/servlet/IBISHTTPUploadServlet/EPM-LFW.C.0002.http-DeleteDefaultValues',
}
});

var store = new Ext.data.Store({
proxy: httpProxy,
autoLoad: true,
autoSave: true,
idProperty: 'entryid',

listeners: {
write: function(){console.log('written');},
exception: function(a, b, c, d, e, f){console.log('Exception!'); console.log(a); console.log(b);console.log(c);console.log(d);console.log(e);},
//exception: function(){console.log('exception');},
load: function(){console.log('load');}
},


reader: new Ext.data.XmlReader({record: 'entry', documentRoot: 'records'}, EntryDef),
writer: new Ext.data.XmlWriter({record: 'entry', documentRoot: 'records'}, EntryDef)
});


var grid = new Ext.grid.GridPanel({
id: 'LFGrid',
store: store,
columns: [
{
id :'EntryID',
header : 'EntryID',
width : 160,
sortable : true,
dataIndex: 'entryid'
},{
id :'Name',
header : 'Name',
width : 160,
sortable : true,
dataIndex: 'name'
},
{
xtype: 'actioncolumn',
width: 50,
items: [{
icon : '/html/JB_GridPanel/icons/settings.png',
tooltip: 'Mit Klick den Eintrag bearbeiten',
handler: function(grid, rowIndex, colIndex) {
loadEntry(rowIndex);
}
}]
}
],


height: 700


});


var btnAdd = new Ext.Button({xtype:'button', text: 'Neuer Eintrag hinzufügen', icon: '/html/JB_GridPanel/icons/add.png', handler: function(){addEntry();}})

//var btnSave = new Ext.Button({xtype:'button', text: 'Speichern', icon: '/html/JB_GridPanel/icons/save.gif', handler: function(){saveEntry();}})




});


function addEntry(){
var gridstore = Ext.getCmp('LFGrid').store;


gridstore.add(new EntryDef({name: 'test'}));
}


The panel is loading as expected and it shows the entries the server served. This is the http-Response for "GetDefaultValues":

<?xml version="1.0" encoding="UTF-8"?>


<records>
<entry>
<entryID>1</entryID>
<name>Name1</name>
</entry>
<entry>
<entryID>2</entryID>
<name>Namasdfgdg 2</name>
</entry>
</records>



When I hit the add-Button the store makes a http-Request to my server which responds the following xml:

<?xml version="1.0" encoding="UTF-8"?>


<records>
<entry>
<entryID>1</entryID>
<name>Name1</name>
</entry>
<entry>
<entryID>2</entryID>
<name>Namasdfgdg 2</name>
</entry>
<entry>
<entryid>3</entryid>
<name>test</name>
</entry>
</records>


But chrome always throws an exception. I tried several different variations like just responding the created record and not the whole list and many other things.

However, at this point I have no clue what to try next. I'm not even sure how to find out what exception has been thrown. :-/


Can anybody give me a hint whats wrong and where the bug might be hidden?


Edit:
Now the new item is shown in the grid but marked with a red little triangle. Do I assume right that this is because of the failed create-action and that it will disappear automatically as soon as the creation has been successful?!

thx in advance!
jblb


btw: I'm using extjs 3.4.1.1

Gary Schlosberg
6 Jan 2015, 3:54 PM
Are you seeing an error message in the browser console?

The red triangle indicates that a record is dirty (edited or new). It should disappear when the record has been synced with server.