0
votes

ProjectInfo: Application build with Master/Detail Fiori template in WebIDE

I have a list on my detail page where each item should link to a new view in the details part of the application when selected.

Detail.controller.js:

onInspectionSelect : function(oEvent) {
         var oBindingContext = oEvent.getParameter(
         "listItem").getBindingContext();
         this.getEventBus().publish("InspectionDetails", "Context", { context : oBindingContext} );

    this.getRouter().myNavToWithoutHash({
       currentView : this.getView(),
       targetViewName : "DOHMH.view.InspectionDetails",
       targetViewType : "XML",
       transition : "slide"
}); },

My InspectionDetails.controller.js:

    onInit : function() {

    var bus = sap.ui.getCore().getEventBus();
    bus.subscribe("InspectionDetails", "Context", this._inspection, this);
},

_inspection : function (channelId, eventId, data) {

    if (data && data.context) {
        this.getView().setBindingContext(data.context);
        var sEntityPath = data.context.getPath();
        this.bindView(sEntityPath);
    }
},

It doesn't work the first time I select a list item from the details page due to the InspectionDetails.controller wasn't subscribed when the select event triggered a publish.

Unfortunately, I have no idea how to architecture it right or how to instantiate the controller in advance to avoid the first call being missed out.

To instantiate the controller within the details controller does not work: jQuery.sap.require("DOHMH.view.InspectionDetails"); (returns 404) because it doesn't know if it's getting the InspectionDetails.view.xml or InspectionDetails.controller.js

Solved- Thanks for all help!

Also found a video solution: https://open.sap.com/courses/fiux1/items/3gZjaL857KYu6MYA06dJEs#66

2

2 Answers

1
votes

Why so complicated? Attach the InspectionDetails view to the specific route and set its binding context in the callback. Of course you have to extend your route to InspectionDetails as you need to pass an ID or whatever of the entity you want to show.

1
votes

I would put the subscribe call on a component that knows about the items list and item detail views. Orchestrating both.

Or, even simpler is to not use the events but use a named model. When you click the item on the list, you set the data for the model say 'currentItem' then your detail view field's that have bindings to 'currentItem>x' will be updated automatically.

You could combine the routing framework and the model technique described to create seamless navigation between views.