PDA

View Full Version : What is the correct way to submit a form?



American horizon
6 Jun 2016, 4:10 AM
Hi, iv'e a store that mantain a list of data about users, call it UserStore.
I've bound it to a grid in order to list its content.
When i double click a row, a form with editable fields is shown, in order to edit the user information.

Actually when i press the "save button", i perform an ajax request that POST a json data to the servlet. i bind the json data in this way:



Ext.Ajax.customRequest({
url: 'titolari',
method: 'post',
headers: { 'Content-Type': 'application/json' },
jsonData: Ext.JSON.encode(btn.up("form").getValues())
});



But i thought that the correct way to do this is to update the UserStore itself with modified record values, and after call the sync() method, instead of use an ex-novo Ajax request.
It is the correct way?

joel.watson
6 Jun 2016, 5:56 AM
Hi--

As with most things, the "right" way depends very much on what you're needing to accomplish, what the workflow in your application looks like, whether it works, etc. There's nothing technically wrong with the way you're doing it; if it were me, I'd probably just update the bound record and sync the store.

Thanks!
Joel

American horizon
6 Jun 2016, 6:47 AM
Hi--

As with most things, the "right" way depends very much on what you're needing to accomplish, what the workflow in your application looks like, whether it works, etc. There's nothing technically wrong with the way you're doing it; if it were me, I'd probably just update the bound record and sync the store.

Thanks!
Joel
The second way is what i thought at beginning, but the sync method works in a manner that i don't understand.

My Store is defined with a proxy that performs some type of call according to the operation to perform (read = get, update=post, insert=put),

Suppose that i've updated and added some record into the store. Once i call the sync() method what really happen?

joel.watson
6 Jun 2016, 6:59 AM
Hi--

The proxy will batch together records based on the type (create, update, remove) into operations. These operations will be executed per the configured batchOrder, and the store will be updated as each operations concludes:

http://docs.sencha.com/extjs/4.2.5/#!/api/Ext.data.AbstractStore-method-sync
http://docs.sencha.com/extjs/4.2.5/#!/api/Ext.data.proxy.Proxy-cfg-batchOrder

Thanks!
Joel