cancel
Showing results for 
Search instead for 
Did you mean: 

Element Binding .refresh( ) does not work after SAPUI5 upgrade

RaminS
Participant
0 Kudos

We have a bunch of custom free-style Fiori apps created a few years ago, that contain code like this in the attachPatternMatched method of the router object:

var oElementBinding = this.getView().getElementBinding();
if ( oElementBinding.getBoundContext() ) {
	oElementBinding.refresh(); 
}

This is to ensure if the user navigates away and then back to an Object page, the view's elementBinding gets refreshed from the backend (because view.bindElement( ) does not call the backend if user navigates away then back to the object page).

This has worked fine so far until we upgraded to SAPUI5 1.71.53 (from 1.71.48), and now it doesn't refresh.

We found that if we add the parameter true, it works as before:

oElementBinding.refresh(true); 

Now, I know we should have had the "true" parameter from the start, but why would that make a difference in 1.71.53, and not 48. The parameter is supposed to only matter if the model has not changed, in our cases the model has changed, so the refresh should work even without the parameter.

Would appreciate any recommendations, on what the proper way is to ensure models are updated as user navigates between pages.

Thanks

Accepted Solutions (0)

Answers (3)

Answers (3)

boghyon
Product and Topic Expert
Product and Topic Expert

Assuming the "model" is of type v2.ODataModel, you can ensure that the bound context fetches always the entity from the OData service by calling sap.ui.model.odata.v2.ODataModel#invalidateEntry before bindElement (or bindObject).

See my other answer at "How to refresh previously bound entity every time user visits the page?"

Most of the times, Model#refresh is not required.

RaminS
Participant
0 Kudos

Thanks a lot, I will try that.

I had already tried unbindElement( ), but it didn't do anything.

Do you have other examples of proper controller logic? I feel like many of us could use more examples, as there are so many different ways of doing things. I've been looking in Github for examples but it's hard to find what youre looking for.

Thanks again.

RaminS
Participant
0 Kudos

I'm curious, how does this refreshing happen in SAP's List Report template? Do they use invalidateEntry in the object page to make sure it refreshes when user navigates from worklist to Object? And how do they ensure Worklist gets refreshed when the user edits something in the Object page? .... Do they use eventBus subscribe/publish events? How do they ensure models get refreshed at the right time?

.

boghyon
Product and Topic Expert
Product and Topic Expert
0 Kudos

ramin.shafai

Templates from SAP Fiori elements (FE) are not really comparable with rather simple freestyle apps since FE implements a number of additional features, such as draft handling, side effects, refreshing in sap-keep-alive, etc., that affect the object page or any other bound elements.

We can see in the current FE V2 source code that invalidateEntry is one of the approaches the Object Page uses to refresh itself unconditionally.

Having to "ensure models get refreshed at the right time" sounds like the application is incorrectly applying changes typically via private properties or unbound model paths. If you need more help, we'd need to look at the application code in a new question.

shobhit2108
Explorer
0 Kudos

Hey Ramin,

As per my knowledge, the code you mentioned should refresh the control (without true parameter) with latest data in the model if the data has changed, provided the binding in proper.

I am not sure as to why it is not working in a specific version but in case if you need to force refresh, you can use the true parameter to refresh the control with latest fetched data.

I think your understanding is correct for the refresh() method and maybe you might need to open a ticket with concerned product team for this specific template issue.

Thanks

Shobhit Pathak

shobhit2108
Explorer
0 Kudos

Hi Ramin,

As per my knowledge the refresh() function fetches data from the back end service and updates the model. It doesn't update the bound controls.

In case you need to update the controls that are are bound to this model,whose data has been changed, you need to pass in the true parameter which forces the controls to be updated.

I think your apps needs to update the bound controls with new data and hence this param would be needed to do so. Without this, your model would definitely show the changes but control would not.

Hope it helps.

Thanks

Shobhit Pathak

RaminS
Participant
0 Kudos

Are you saying this:

this.getView().getElementBinding().refresh(); 

does not refresh the view controls?