cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SAPUI5 runtime context and browser refresh

Former Member
0 Likes
2,900

Hi,

I observed the following behaviour: I created a navigation path and a number of models to be used in my App. The models are created in Component.js means centrally. I can easily access them from my MainView by this.getModel(). In the target View I am processing the model content. To access it there, I run

var oModelAnchor = sap.ui.getCore().byId(cModelAnchorViewID);
var oModelL = oModelAnchor.getModel(cModelName);

cModelAnchorViewID is the view ID of the main View and cModelName is containing the name of the model. Modeltype is JSON the viewtypes are XML and javascript. Code works fine as long as I use the implemented sapui5 navigation functionality.

As soon as I am refreshing the page, when I am on the target view by using the browser refresh button, the runtime context changes. My anchor view is not longer accessible and the first line of code is returning undefined. To work around the problem I declared the model locally to this view.

Any ideas why this happens? Obviously this behaviour is having significiant impact on how to implement value handling along navigation paths.

thanks for feedback.

WPdat

Accepted Solutions (1)

Accepted Solutions (1)

sebastianraemsch
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi Wolfgang,

I´m not sure if this helps but I used


sap.ui.getCore().setModel()

and


sap.ui.getCore().getModel()

for my models which I have to access from different views. My development environment is currently broken so I cannot test if this solves the issue with page refresh. But maybe you give it a try.

Best regards,

Sebastian

Former Member
0 Likes

Hi Sebastian,

thanks for your hint. Unluckily both methods do not return a valid model in the given runtime context.

best regards

Wolfgang

sebastianraemsch
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi Wolfgang,

Today my dev environment is working again and I tested it.

In component.js I set a global model:


// define a global model for global properties / attributes (global variables/ settings)

var oGlobalProperties = {

sServiceUrl: sServiceUrl,

mockserver: {

  isStarted: bIsMocked

}

};

var oGlobalJSONModel = new sap.ui.model.json.JSONModel(oGlobalProperties);

sap.ui.getCore().setModel(oGlobalJSONModel, "GlobalProperties");

Then I can access the model from anywhere in my app by calling

sap.ui.getCore().getModel("GlobalProperties")

So, not sure what´s different in your app and what you exactly tried but this works for me and it works perfectly after refreshing the page by pressing F5.

Best regards,

Sebastian

former_member186566
Active Participant
0 Likes

Hi Sebastian Raemsch

Im facing the same issue.

Your suggestion is working, but i want to change Json dynamically when its navigating from 1st view to 2nd view.

I have posted new thread here https://scn.sap.com/message/16511272#16511272

Can you help me to resolve this issue ?

Thanks & Regards

Yokesvaran Kumarasamy

Answers (2)

Answers (2)

Former Member
0 Likes

hi,

I had the same problem in my fiori launchpad because of change of id of the views when refreshing.What i did was i get the view id in onInit() method and used it.This solved my problem

hope this helps

Regards

Former Member
0 Likes

Hi Rajeesh,

thanks a lot. It is not selving the problem itself but it is usefull workaround. Quite helpfull.

best regards

Wolfgang

junwu
SAP Champion
SAP Champion
0 Likes

why go through the view?

did you try to access model in your controller? this.getOwnerComponent().getModel()

Former Member
0 Likes

Thanks for replay. Good Point. The reason is, that I want to access i18n model in various scenarios. Access to it is not working in some of my views and especially not if I am opening a dialog window using a view. This view instance does even not have a this.getOwnerComponent() method. Is there a way how to access this model independend from navigation status ? sap.ui.getCore().getModel(<modelName>) is not working this way. Using the proposed syntax "{i18n>textName}" leaves the text entities empty also. Any input is very welcome.