cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5 oDataModel setDeferredGroups autofiring requests

Former Member

When I have an oDataModel v2 with two-way binding and I call the setDeferredGroups() method it then changes the default behavior of all data changes to no longer be deferred.

We can see here in this documentation under 'Two-way Binding' it says: "Per default, all changes are collected in a batch group called "changes" which is set to deferred. To submit the changes, use submitChanges()."

This is true. If I do not call the function setDeferredGroups() then all of my data changes do not fire any requests automatically. No requests are sent until I manually call oModel.submitChanges() as expected.

Now in the same article under the heading 'Batch Processing':

"For each binding and each manual request, a groupId can be specified. All requests belonging to the same group are bundled into one batch request. Request without a groupId are bundled in the default batch group."

I decide I want to be able to push a group of changes by giving them a groupId so I call the function as shown in the guide like so:

oModel.setDeferredGroups(["myGroupId"]); 

Then, for example, I create an entry like so:

oModel.createEntry("/RANDOM_ENTITY", {
    groupId : "myGroupId"
});

And I change no other code at all. This works as expected, and I am able to call the submitChanges() function passing in the groupId:

oModel.submitChanges({
    groupId : "myGroupId"
}); 

Now the issue is that in doing this it then sets the default behavior of all changes that do not set this groupId to be not deferred (despite all changes are deferred by standard). All changes by default are deferred but if you call this function it changes it so that only the changes with the groupId's given are deferred.

This means that every time I change my data for any entity without setting a groupId it will trigger a request to the server. E.g. changing a two-way bound field on the screen will send a network request the second it loses focus. Instead of waiting for me to call oModel.submitChanges().

So my questions are:

1. Is there a way to set the default behavior back to deferred for all requests?
2. How do I submitChanges() a subset of changes if not by setting groupId?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member

Turns out the default deferred group called 'changes' is overwritten by 'setDeferredGroups' but can first be retrieved through 'getDeferredGroups'. So instead I needed to:

    oModel.setDeferredGroups(oModel.getDeferredGroups().concat(["myGroupId"]));

Answers (2)

Answers (2)

Fjaoos
Participant
0 Kudos

Thank you so much for that fix. Can someone pls explain we, why this is not documented???

Margot
Product and Topic Expert
Product and Topic Expert
0 Kudos

Thanks for making us aware of this gap in the documentation. I reported this back to the responsible team and a fix is on its way to improve the API reference documentation accordingly.

Feel free to open a GitHub Issue on the OpenUI5 Repo next time you may experience a similar situation or via the SAPUI5 demo kit feedback channel (in case it relates to SAPUI5 only).

0 Kudos

thanks, i met the same problem, and fixed in this way.