Skip to Content
avatar image
Former Member

SAPUI5 oDataModel setDeferredGroups autofiring requests

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?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    avatar image
    Former Member
    Oct 19, 2017 at 03:24 AM

    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"]));
    Add comment
    10|10000 characters needed characters exceeded