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

SAPUI5 runtime context and browser refresh

Former Member
0 Likes
2,906

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

View Entire Topic
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