Skip to Content
Author's profile photo Former Member

Application data between different views

Hi,

        This blog is specially for the SAP UI5 beginners. It is related on ‘How to control application data between different views at runtime’. If you want to use data between several views and/or controllers but you don’t want to use global javascript variable directly, you can use the SAPUI5 core to persist the data.

In this case you need to create an new attribute of type Object on the SAPUI5 core and persist the data in this attribute.

Now you are able to access this context data within the whole SAPUI5 application. Another big advantage of this approach will be that the context data is not visible directly for the outside world as a global object.

Below you will find an example how you can declare the context attribute and how you can use these in your SAPUI5 application.

index.html

<!DOCTYPE HTML>

<html>

<head>

<meta http-equiv=”X-UA-Compatible” content=”IE=edge”>  <script src=”resources/sap-ui-core.js”

id=”sap-ui-bootstrap”

data-sap-ui-libs=”sap.ui.commons”

data-sap-ui-theme=”sap_goldreflection”>

</script><script>

              sap.ui.getCore().AppContext = new Object();

              sap.ui.getCore().AppContext.Language = “Dutch”;

sap.ui.localResources(“exampleapplicationdatastore”);

var view = sap.ui.view({id:”idAppView1″, viewName:”exampleapplicationdatastore.AppView”, type:sap.ui.core.mvc.ViewType.JS});

view.placeAt(“content”);

</script>

</head><body class=”sapUiBody” role=”application”>

<div id=”content”></div>

</body>

</html>

AppView.View.js

sap.ui.jsview(“exampleapplicationdatastore.AppView”,{

getControllerName : function() {

return “exampleapplicationdatastore.AppView”;

},createContent : function(oController) {var oButton = new sap.ui.commons.Button(“btn1″, {text:sap.ui.getCore().AppContext.Language

});

return oButton;

}});

Now you can use the Application Context everywhere in the SAPUI5 application.


Reffered from: Code Snippets

  

                  

Assigned tags

      2 Comments
      Comments are closed.
      Author's profile photo Former Member
      Former Member

      Hello,

      As we are building a solution on SAPUI5 for fiori, we had looked at this blog with lots of enthusiasm, but this looks to be in-line with the details and code snippet in the below link.

      How to control application data between different views at runtime - SAPUI5.ORG

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hi Diptanu,

      As i found this info is useful for beginners I had posted this blog rather than providing a link.

      Regards,

      Anusha