Search code examples
sapui5sap-fiori

Fiori -- Cross application navigation; Handling startup parameters?


This question is related to:

My use case is like this:

I have multiple applications that should link to others (deep). Since documentation of cross navigation mention to avoid deep links I decided to use a startup parameter.

For example:

Application A has a list of some items in the detail view of one item there is a reference to another application B that contains some other details. Assume A shows article details and B shows some details of a producer of an article.

Application A would now use some navigation like this:

sap.ushell.Container.getService("CrossApplicationNavigation").hrefForExternal({
  target : { semanticObject : "ApplicationB", action : "display" },
  params : { "someID" : "102343333"}
})

Now in application B I use code like this inside the Component.js at the end of the init method.

var oRouter = that.getRouter().initialize();
var oComponentData = this.getComponentData();
if (oComponentData.startupParameters) {
    oRouter.navTo("SomeView", {
        someId : oComponentData.startupParameters.someID[0],
    }, false);
}

First question: Is this the right place for handling the startup parameters?

Second question: If I using the navigation the startup parameter will still be in the code, I would prefer to remove it, but how?

Update

In the target application (B) it would lead to the following URL:

https://server/sap/bc/ui5_ui5/ui2/ushell/shells/abap/FioriLaunchpad.html?sap-client=100&sap-language=EN#SemObject-display?someID=102343333&/SomeView(102343333)/

Anyhow I would prefere to have something like this:

https://server/sap/bc/ui5_ui5/ui2/ushell/shells/abap/FioriLaunchpad.html?sap-client=100&sap-language=EN#SemObject-display?/SomeView(102343333)/

Solution

  • The parameter must be retrieved as

    var oComponentData = this.getComponentData();
    if (oComponentData.startupParameters) {
        oRouter.navTo("SomeView", {
            someId : oComponentData.startupParameters.someID[0],
        }, false);
    

    as you write. In Fiori applications, the startup parameters injected into the Component data of your constructor may have been renamed, enriched by further default values etc.. Thus they may be distinct from the parameter one observes in the url. Applications are advised to refrain from trying to inspect the URL directly.

    If one supplies a very long set of url parameters, one will observer that the FLP replaces some of them with sap-intent-param=AS123424 ("compacted URL") to work around url length restrictions on some platforms and in bookmarks, in the getComponentData().startupParameters one will receive the full set of parameters).

    As to the second question. No, there is currently no way to "cleanse" the URL and avoid the redundancy between and inner app route.

    SemObject-display?someID=102343333&/SomeView(102343333)/ which after navigation may look like SemObject-display?someID=102343333&/SomeView(102343999)/

    App was started with 102343333, but then user navigated within the app to another item (102343999).

    Any change in the "Shell-part" of the has (SemObject-display?someID102343333) will lead to a cross-app-navigation (reinstantiation of your component) with a different startupParameter.

    (There are cases where this is desired in the flow, e.g. a cross navigation from a OrgUnit factsheet to the parent OrgUnit factsheet via a link).

    There were ideas within SAP to fuse the inner-app routes and the intent parameters, but they were not carried out, as it's mostly url aesthetics.

    Note: To support boomarking, one has to respect both startup parameters and inner app route during component instantiation, assuming the user created a bookmark on

    SemObject-display?someID=102343333&/SomeView(102343999)/ (While he was looking at 9999(!)).

    When reinstantiating the app, the inner app route should take higher precedence than startup-parameters.

    So amend the code to:

    var oComponentData = this.getComponentData();
    if (oComponentData.startupParameters) {
        if (sap.ui.core.getHashChanger().getHash()=== "") {
             // if no inner app route present, navigate 
             oRouter.navTo("SomeView", {
                   someId : oComponentData.startupParameters.someID[0],
             }, false);
        }
    

    }

    https://sapui5.netweaver.ondemand.com/#docs/api/symbols/sap.ushell.services.CrossApplicationNavigation.html

    SAP Fiori Launchpad for Developers, Navigation Concept http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/907ae317-cb47-3210-9bba-e1b5e70e5c79?QuickLink=index&overridelayout=true&59575491523067