I created a UI5 master-detail page:
Master
<List items="{som>/Users}">
<StandardListItem
type="Navigation"
press="onItemPress"
title="{som>UserName}"
/>
</List>
onItemPress: function(oEvent) {
var oUserContext = oEvent.getSource().getBindingContext("som");
var oUser = oUserContext.getObject();
this.getRouter().navTo("userDetails", {userId: oUser.Id});
}
Detail
onInit: function () {
var route = this.getRouter().getRoute("userDetails");
route.attachPatternMatched(this._onObjectMatched, this);
},
_onObjectMatched: function (oEvent) {
var sUserId = oEvent.getParameter("arguments").userId;
this.getView().bindElement({
path: "som>/Users('"+sUserId+"')",
model: "som"
});
},
reload: function() {
this.getView().getModel("som").refresh();
},
<fLayout:SimpleForm id="userForm">
<Button text="reload" press="reload"/>
<Label text="{i18n>settings.user.id}"/>
<Input editable="false" value="{som>Id}"/>
<Label text="{i18n>settings.user.username}"/>
<Input value="{som>UserName}"/>
<Label text="{i18n>settings.user.email}"/>
<Input value="{som>Email}"/>
<Label text="{i18n>settings.user.firstname}"/>
<Input value="{som>FirstName}"/>
<Label text="{i18n>settings.user.lastname}"/>
<Input value="{som>LastName}"/>
</fLayout:SimpleForm>
Everything is working fine. But when I change a user in the detail view, it is being updated but not in the master view! With the reload method, I can manually refresh it. But how can I fire this automatically after a change? Can I bind a change event on the SimpleForm?
V4 model works with promise.
When submit the changes you can use .then(), so you can refresh the model.
https://sapui5.hana.ondemand.com/#/api/sap.ui.model.odata.v4.ODataModel/methods/submitBatch
Here is a working example: https://embed.plnkr.co/qatUyq/?show=preview
We need to keep in mind that v4.ODataModel is still work in progress. E.g. the synchronization mode has to be
"None"
currently.Therefore, the application itself has to identify related bindings and refresh them manually. To make it efficient, we can send such GET requests together with the update request via batch group ID which is what v2.ODataModel automatically does (unless
refreshAfterChange
is disabled).In the example above, I used the following settings and APIs:
$$updateGroupId: "myGroupId"
for context binding (detail page)refresh("myGroupId")
from list binding (master list)submitBatch("myGroupId")
.If we then inspect the request payload, we can see that the PATCH and GET requests are bundled together. Hence, the master list is refreshed at the same time.
Q&A
What is the default binding mode in v4.ODataModel?
"TwoWay"
- The UI changes the model data and the other way around. When the change is not stored in a batch queue, the corresponding request is sent immediately.How do I know if I'm using batch mode or not?
$$groupId
for read, and certain bindings support$$updateGroupId
for update requests."$direct"
, the corresponding requests are sent directly without batch. Those requests are easier to diagnose and cacheable by the browser.submitBatch
."$auto"
, meaning by default, requests are sent as batch automatically when the corresponding control gets (re)rendered.submitBatch
without adding the groups to "deferred groups" beforehand like I did with v2.ODataModel?requestSent
andrequestCompleted
. Why can't I make use of them in v4.ODataModel?Hope I made some things more clear. The latest documentation about OData V4 in UI5 can be found in: https://openui5nightly.hana.ondemand.com/#/topic/5de13cf4dd1f4a3480f7e2eaaee3f5b8