Skip to Content
avatar image
Former Member

how work with global variables sapui5

hi, i hope can you help me,

If using global variables to store data is bad practice, how could I keep the user data obtained from a web service, I mean the data not as critical as the username to display it throughout the app?

I have read about sap.ui.getCore (). AppContext = new Object (); Or using a json model,

If that is the json, how would you use the code, in this way?

Controller:

Var oModelLogin = new myJSONModel ("model / UserModel.json");
OModelLogin.loadDataNew ("linkwebservice", handleSuccess, handleError, oParameters, true, 'GET') 

View:

New sap.m.Link ({
Text: "{/ UserModel> personUserName}",
Press: function () {
OController.onSendPassword ();
}
}). AddStyleClass ("sapUiTinyMarginTop")
]

Thank you very much I could give some suggestions, thanks in advance.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Mar 14, 2017 at 06:17 PM

    create a oData Model at component level which will act as a global model for all the views and controllers

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Srikanth KV

      Thank you for your suggestion Has worked and I'm getting the model of the component through different views.

      But now another problem arises, when I update the page in an application view the data of the model are lost, as I call them from a web service when starting the login of the application, When the user logs in, checks and queries the data through a web service, then stores the user's data in the model of the component, but then once entered into the application if a view is updated, the model is lost. How can I handle this situation, can you use Sessions on sapui5? Would you have any suggestions for this case? Thanks in advance.