Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
777 views
in Technique[技术] by (71.8m points)

Success-Callback after SubmitChanges not called (SAPUI5 OData)

I'm working with OData V2 Model with enabled batch-support.

When the backend process is running without throwing any exceptions, the Success-Callback is never called.

But when there's a backend exception, the Success-Callback is called (not error-callback, Bug?). Therefore I'm checking for the statuscode in the Success-Callback.

Is there another possibility to get the statuscode or a success-callback in general? Maybe with attachBatchRequestCompleted?

Binding to View:

this.setModel(this.getOwnerComponent().getModel());
this.getModel().metadataLoaded().then(function () {
    var sObjectPath = this.getModel().createKey(sEntity, { 
        UserId: sUserId
    });
    this.getView().bindElement({
        path: "/" + sObjectPath
    });
}.bind(this));

Submit-Call:

this.getView().getModel().submitChanges({ 
                                success: function (oData) {
                                    try {
                                        if (oData.__batchResponses[0].response.statusCode >= 400) {
                                            //Error
                                        }
                                    } catch (err) {
                                    },
                            error: function (oError) {
                            });
question from:https://stackoverflow.com/questions/65831481/success-callback-after-submitchanges-not-called-sapui5-odata

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This depends on the batch mode setting (see setBatchMode)

If batch mode is off, the success callbacks are not called at all (see submitChanges).

If batch mode is on, the success callback is called, if the batch is successful even if some of the actual requests within the batch fail.

The error callback is called, if the actual batch failed (almost never - except during development).

If requests are aborted, the handlers are called as follows (see submitChanges)

If there are no changes/requests or all contained requests are aborted before a batch request returns, the success handler will be called with an empty response object. If the abort method on the return object is called, all contained batch requests will be aborted and the error handler will be called for each of them.

PS: you can use sap.ui.core.message.MessageManager to display errors in a standardized way.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...