PDA

View Full Version : directStore with a JsonWriter sends no data with autoSave: true



bareflix
13 Jun 2010, 2:31 PM
I have a directStore hooked up to a list and an edit form. It reads the data from the backend correctly, but when it saves, the data field is null. If I call store.save(), then it send the data for ALL rows, not just the ones that have changed. Here is my store setup:


skillStore = Ext.extend(Ext.data.DirectStore,
{
constructor: function (config)
{
var params =
{
autoLoad: true,
autoSave: true,
paramsAsHash: false,
totalProperty: 'count',
root: 'result',
paramsAsHash: false,
api:
{
//create: CRUD.create,
read: orbital.Skill.read,
update: orbital.Skill.update,
//destroy: CRUD.destroy
},
// I don't know why the writer does not get auto created like the reader
writer: new Ext.data.JsonWriter(
{
returnJson: true,
writeAllFields: true
}),
storeId: 'skill',
fields:
[
{name:'id', type: 'number'},
{name:'name', type: 'string'},
{name:'default_attribute', type: 'string'},
{name:'description', type: 'string'},
{name:'type', type: 'string'}
],
};

config = Ext.apply (params, config);
skillStore.superclass.constructor.call(this, config);
}
});

Here is what it sends when I call:
this.getForm().updateRecord(this.record);


{"action":"Skill","method":"update","data":null,"type":"rpc","tid":3}

any suggestions? what am I missing?
It's taken me a while to get here, but it seems so close.

--
Chris Bare

Condor
13 Jun 2010, 10:16 PM
You need to configure your writer with encode:false.

bareflix
14 Jun 2010, 9:44 AM
I tried adding encode: false to the writer, but I still get the same "data":null sent to the backend.

bareflix
14 Jun 2010, 11:05 AM
actually I do see one difference. it says "result": null, which is the value I set in the DirectStore for root:

I see the updated value displayed in my grid, but is it possible that the store is not seeing the updated record? Here's what my form save does:

this.getForm().updateRecord(this.record);

which comes from the list via:

var rec = this.list.getSelectionModel().getSelected();
this.form.loadRecord(rec);

bareflix
15 Jun 2010, 3:27 PM
ok, I built a cut-down test case and it is still not working. I am using version 3.2.1. Here's my test case:


<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="ext/resources/css/ext-all.css">
<link rel="stylesheet" type="text/css" href="css/orbital.css">
</head>

<body>
<script type="text/javascript" src="ext/adapter/ext/ext-base.js"></script>

<script type="text/javascript" src="ext/ext-all-debug.js"></script>
<script type="text/javascript" src="php/api.php"></script>

<script type="text/javascript">

// Path to the blank image must point to a valid location on your server
Ext.BLANK_IMAGE_URL = 'ext/resources/images/default/s.gif';

function modify ()
{
var rec = list.getSelectionModel().getSelected();
rec.set ("description", "value");
store.save ();
}

orbital.API.maxRetries = 0;
Ext.Direct.addProvider(orbital.API);

store = new Ext.data.DirectStore (
{
autoLoad: true,
autoSave: false,
root: 'result',
api:
{
//create: CRUD.create,
read: orbital.Skill.read,
update: orbital.Skill.update,
//destroy: CRUD.destroy
},
// I don't know why the writer does not get auto created
writer: new Ext.data.JsonWriter(
{
encode: false,
writeAllFields: true
}),

fields:
[
{name:'id', type: 'number'},
{name:'name', type: 'string'},
{name:'default_attribute', type: 'string'},
{name:'description', type: 'string'},
{name:'type', type: 'string'}
],
});

list = new Ext.grid.GridPanel (
{
region: 'center',
store: store,
columns: [
{header: 'ID', sortable: true, dataIndex: 'id'},
{header: 'Name', sortable: true, dataIndex: 'name'},
{header: 'Default Attribute', sortable: true, dataIndex: 'default_attribute'},
{id: 'description', header: 'Description', sortable: true, dataIndex: 'description'},
{header: 'Type', sortable: true, dataIndex: 'type'}
]

});

button = new Ext.Button (
{
region: 'south',
text: "modify"
});

button.on ('click', modify);

function main ()
{
viewport = new Ext.Viewport(
{
layout: 'border',
items:
[
list, button
]
});
}


// Main application entry point
Ext.onReady( main );

</script>
</body>

</html>

and here's what it sends when you press the modify button:

{"action":"Skill","method":"update","data":null,"type":"rpc","tid":3}


I tried tracing the save function and I saw writer.json had the updated record, but I got lost in all the layers of callbacks etc.
what am I missing?

--
Chris Bare

freak_out
1 Apr 2011, 3:51 AM
Hi, I have the same problem. Have you found a solution to this?
Thanks

bareflix
1 Apr 2011, 7:19 AM
It's been a while, but I *think* my problem was that my backend function was declared with no parameters. I just stubbed it out, thinking I would finish it once I got the javascript side working. Well, since ext direct knows the function signature, it takes that into account and doesn't send anything if your function doesn't take any parameters.

milanz
14 Aug 2011, 8:40 AM
You just saved me a whole load of time.

I was also trying to get it to work, thinking I'll just create a method stub (not thinking to add any arguments to the method). Added an argument to the method and BINGO - data sent!

Thanks!