cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5 Two-way binding: How do I clear/refresh the binding every time I navigate to the app?

adamharkus
Participant
0 Kudos

I have an issue with two-way binding when returning to a freestyle SAPUI5 app.

Say for example...

I navigate to App 1. The loads the OData fine, via two-way binding.

I then navigate away from App 1 to App 2. This also loads the OData for App 2 fine.

Now when I navigate back to App 1, The OData isn't loaded again, with the binding remaining from the first time into App 1.

I then navigate to App 2, same issue, the OData isn't reloaded, and the binding from the first entry into App 2 remains.

Ideally, I would like the binding cleared every time I enter an app, be it the 1st time in (initialization) or when navigating to it.

Is this possible to do with manifest properties? (much preferable) Or will a refresh need to be triggered in the controller?

Accepted Solutions (0)

Answers (3)

Answers (3)

yogananda
Product and Topic Expert
Product and Topic Expert

adamharkus

I think, what you want to do is to bind the data each time you enter the app. You can use the <code>constructor</code> of the controller to bind the data.

onstructor: function (oView) {
    this.oView = oView;
    this._oDataModel = this.oView.getModel();
    this.oView.bindElement({
        path: "/path/to/data"
    });
    this.oView.setModel(this._oDataModel);
},

Whenever you enter the app, the constructor will be called and the <code>bindElement</code> will be executed and your data will be binded.

adamharkus
Participant

Also, unBindElement does the job.

Thanks a lot yoganandamuthaiah

0 Kudos

Hello Adam,

in order for the binding using the same path to make a request again and update the data, you need to invalidate the previous result in the model.

//check if model has some objects
if (!(Object.keys(this.getView().getModel().getData('/')).length === 0)) {
// make the path for current Entry
sPath = this.getView().getModel().createKey("/SomeSet", {
Key1: sKey1,
...
KeyN: sKeyN
});

this.getView().getModel().invalidateEntry(sPath);
} else {
sPath = ["/SomeSet(Key1='", sKey1, ... ,"',KeyN='", sKeyN, "')"].join("");
}
this.getView().bindElement({
path: sPath,
events : {
dataReceived: function(oEvent) {
...
}.bind(this)
}
});
junwu
Active Contributor
0 Kudos