Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

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

  

                  

2 Comments
Labels in this area