PDA

View Full Version : Hint on how to save store changes to a database/webservice



HerrB
22 Jun 2009, 10:29 AM
Could someone could post a hint/an example, how the changes in a store (e.g. TreeStore) may be saved into a database e.g. using a webservice?

Do I have to add a listener to the store update event and there has to be which element to send the new object/the request for the new object to a webservice?

Currently I'm combining a HTTPProxy (getting the data from an ASP.NET webservice), a JSONLoader and a TreeStore to get a tree where I can add new elements - but changes to the store (e.g. an "add new model") doesn't send anything to the webservice. I thought, that changes in the store are getting transmitted via the HTTPProxy back to the server (which is not the case, I think now).

Sorry, if this is a stupid question, but I haven't found any information how to do this in Ext GWT.

*Please*

Regards,

HerrB

jadrake75
22 Jun 2009, 2:17 PM
Hi HerrB,
My application works similiarly (although my backend is Java REST based), but I didn't want to go with RPC since I support a mobile application written in C# (and have other uses for my services)

The way you do this is to listen for a store change and then post your serialized data to the correct web service. In the case of REST this is combination of HTTP Method+URI. To facilitate this, I actually created my own RestfulModelController which processes the get/put/delete/post handling. Within this, you basically need to create a RequestBuilder to your webservice, set your request data (your serialized data) and then send() the request (implementing an onError( ) or onResponseRecieved( ) methods). There should be plenty of examples of GWT RequestBuilder AJAX posts (this is a GWT not GXT functionality)

Depending on your design, you may simply need know the status of the operation (for example receiving a {success:true} to know that the create/update was successful and thus can be reflected in the tree model. How and when you choose to update your UI will depends on this. One approach could be to leverage the "setModifiedChanges" and only post updates when the user "Saves( )" or only commit changes when you receive a successful server response.

-Jason

HerrB
23 Jun 2009, 2:05 AM
Thank you, this was the information I needed. I will post an example, if it is available.

Regards,

HerrB