Handling of startup parameters that are encoded in the URL.
An app can dynamically pass parameters to another app using the CrossApplicationNavigation service. The following code snippet shows an example:
var href_For_Product_display = ( sap.ushell && sap.ushell.Container && sap.ushell.Container.getService("CrossApplicationNavigation").hrefForExternal({ target : { semanticObject : "Product", action : "display" }, params : { "ProductID" : "102343333", SupplierId : "90210" } })) || "";
Startup parameters are received by an embedded component by calling the getComponentData method, which returns a startupParameters member. The following code snippet shows an example:
sap.ui.core.UIComponent.extend("AppNavSample.Component", { ... createContent : function() { /* * getComponentData() returns an object like { startupParameters : { AAA : ["BBB"], DEF: ["HIJ","KLM"] } } * NOTE: parameters values are passed via arrays */ var oComponentData = this.getComponentData(); jQuery.sap.log("app was started with parameters " + JSON.stringify(oComponentData.startupParameters || {} )); ... } });
The parameter values are always passed into an array inside the object returned by getComponentData().
For views created by the SAPUI5 routing framework or directly from within the component, you can locate and identify the component using getOwnerIdFor. The following code snippet shows an example:
// view controller. getMyComponent: function() { "use strict"; var sComponentId = sap.ui.core.Component.getOwnerIdFor(this.getView()); return sap.ui.component(sComponentId); } onCreate : function() { … var oStartupParameters = this.getMyComponent().getComponentData().startupParameters; } ...
For more information, see sap.ui.core.Component.
To set startup parameters for an app, the following options exist:
If you use a stand-alone index page for testing your app in a local environment, you can pass the query parameters to the component as shown in the following example:
<head> … <script> var oStartupParameters = jQuery.sap.getUriParameters().mParams; var oComponent = sap.ui.getCore().createComponent({ name: "sap.samples.SampleComponent", settings: { componentData: { startupParameters: oStartupParameters } } }); new sap.ui.core.ComponentContainer({ component: oComponent }).placeAt("content"); </script> </head> <body> <div id=”content”/> </body>