2

Im creating an app to display recommendation results for apps to users but cannot display it on the app.

The error shows Display property undefined in my Base Controller file

Error Code is getOwnerComponent("myComp").getTargets().display(to) is in appview.controller.js file (controller file)

NOTE :if i use method 1 for the component container , i can initialise router but error is targets undefined as component id is not found.

However if i use method 2 for the component container , i can getOwnerComponent but display undefined as i cannot initialise router.

Any Ideas?

appview.controller.js

 handlePressOpenMenu: function(oEvent) {
      var oButton = oEvent.getSource();
      // create menu only once
      if (!this._menu) {
        this._menu = sap.ui.xmlfragment("apps.html.fragment.view_menu", this);
        this.getView().addDependent(this._menu);
      }
      var eDock = sap.ui.core.Popup.Dock;
      this._menu.open(this._bKeyboard, oButton, eDock.BeginTop, eDock.BeginBottom, oButton);
    },
    handleMenuItemPress: function(oEvent) {
      if (oEvent.getParameter("item").getSubmenu()) {
        return;
      }
      var to = oEvent.getParameter("item").data("to");
      if (to) {
        this.getOwnerComponent("myComp").getTargets().display(to);
      }

    },
    

manifest.json

"routing": {
            "config": {
                "routerClass": "sap.m.routing.Router",
                "viewType": "XML",
                "async": true,
                "viewPath": "apps.html",
                "controlAggregation": "pages",
                "controlId": "idAppControl",
                "transition": "slide"
            },
            "routes": [{
                "name": "appview",
                "pattern": "",
                "target": ["appview"]
            }],
            "targets": {
                "appview": {
                   "clearAggregation": true,
                    "viewName": "appview"
                },
                 "xsodata.collaborative": {
                  "clearAggregation": true,
                  "viewName": "xsodata.collaborative"
                },
                 "xsodata.contentbased": {
                  "clearAggregation": true,
                  "viewName": "xsodata.contentbased"
                },
                "xsjs.apl_recommendation": {
                  "clearAggregation": true,
                  "viewName": "xsjs.apl_recommendation"
                },
                   "xsjs.pal_apriori": {
                  "clearAggregation": true,
                  "viewName": "xsjs.pal_apriori"
                    
                }
}
}
}
}
}

    

component.js

    return UIComponent.extend("apps.html.Component", {

        metadata: {
            manifest: "json"
        },

        /**
         * The component is initialized by UI5 automatically during the startup of the app and calls the init method once.
         * @public
         * @override
         */
        init: function () {
            // call the base component's init function
            sap.ui.core.UIComponent.prototype.init.apply(this, arguments);

            
            // set the device model
            this.setModel(models.createDeviceModel(), "device");

            // initialise router
             this.getRouter().initialise();
            



        }
    });
});

index.html Method 1

sap.ui.getCore().attachInit(function() {
                
                new sap.m.Shell({
     
                    app: new sap.ui.core.ComponentContainer({
                        id:"myComp",
                        height : "100%",
                        name : "movielens.html",
                        propagateModel:true
                    }).placeAt("content")
                });
    

index html Method 2

sap.ui.getCore().attachInit(function() {
                var oComp =  sap.ui.getCore().createComponent({
                        name:"apps.html",
                        id:"myComp",
                        height:"100%",
                        propagateModel:true
                    });
                new sap.m.Shell({
     
                    app: new sap.ui.core.ComponentContainer({
                    component:oComp
                    }).placeAt("content")
                });
            

the exepcted result is supposed to be display of recommendation based on user selection.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Brandon
  • 21
  • 2

0 Answers0