Skip to Content
0
Former Member
Oct 06, 2015 at 09:24 PM

JSONModel & writing to a RESTful backend

63 Views

Hi,

Being a SAPUI5 beginner I have some conceptual questions about the sap.ui.model.json.JSONModel in combination with a RESTful backend: What is the best practice to implement writing operations (create, update, delete) to the backend?

I found countless examples how to read from the REST backend but still have to find a CRUD example with a JSONModel and a RESTful backend. My understanding is - an please correct me - that a OData model is able to automatically sync the model with the backend OData interface and that a JSON model cannot do this automatically with a RESTful service.

Think of a sap.ui.table.Table populated with data from a JSONModel which read from a REST backend. I guess I need to create e.g. a delete button and from its event handler delete the corresponding row in the table (which automatically deletes the record in the model thanks to two way binding) and in addition to that send a DELETE via Ajax to the backend. I guess, trying to send the delete back to the server first and then remove the row in the table and model would be better, allowing for error handling if there was an issue on the backend side. But this needs to be implemented for every create/update/delete operation in the whole application.

Wouldn't it be better to extend the JSONModel so it syncs the model to the backend server automatically? (Just for reference: Lindsay Stanger posted a nice blog post about extending the JSONModel with a bit of a different goal but I can imagine her post would be a starting point: Extending a control in the SAPUI5 library: sap.ui.model.json.JSONModel). I'm not sure how to properly handle errors from the backend side in this case. E.g. if a delete fails on the backend, also prevent the deletion in the table/model and present an error message.

I'm simply not sure whether I'm on the right track because this issue should affect lots of SAPUI5 users but I have not seen it solved, yet. So maybe I'm completely off...

Thank you and regards,

Erich