5

I am on my way building a Fiori like app using SAPUI5. I have successfully built the Master page, and on item click, I pass the context and navigate to Detail page.

The context path from Master page is something like /SUPPLIER("NAME"). The function in App.controoler.js is as follows:

handleListItemPress: function(evt) {
  var context = evt.getSource().getBindingContext();
  this.myNavContainer.to("Detail", context);
  // ...
},

But I would like to know how I can access this context in the Detail page. I need this because I need to use $expand to build the URL and bind the items to a table.

0

2 Answers 2

1

There is an example in the UI5 Documentation on how to deal with this problem using an EventDelegate for the onBeforeShow function which is called by the framework automatically. I adapted it to your use case:

this.myNavContainer.to("Detail", context); // trigger navigation and hand over a data object
// and where the detail page is implemented:
myDetailPage.addEventDelegate({
  onBeforeShow: function(evt) {
    var context = evt.data.context;
  }
});

The evt.data object contains all data you put in to(<pageId>, <data>). You could log it to the console to see the structure of the evt object.

-1

Please refer the "shopping cart" example in SAP UI5 Demo Kit.

https://sapui5.hana.ondemand.com/sdk/test-resources/sap/m/demokit/cart/index.html?responderOn=true

Generally, in 'Component.js', the routes shall be configured for the different views.

And in the views, the route has to be listened to. Please see below.

In Component.js:

routes: [
      { pattern: "cart",
        name: "cart",
    view: "Cart",
    targetAggregation: "masterPages"
      }
        ]

And in Cart.controller.js, the route has to be listened. In this example, cart is a detail

    onInit : function () {
         this._router = sap.ui.core.UIComponent.getRouterFor(this);
         this._router.attachRoutePatternMatched(this._routePatternMatched, this);
   },

    _routePatternMatched : function(oEvent) {
    if (oEvent.getParameter("name") === "cart") {
        //set selection of list back
        var oEntryList = this.getView().byId("entryList");
        oEntryList.removeSelections();
    }
}

Hope this helps.

1
  • Using the Router is the recommended approach but it's not solving the question. Aug 25, 2020 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.