Skip to Content
0

SAPUI5 ROuting with parameters _Object matched event nor fired

Feb 16 at 09:47 PM

139

avatar image

I am working on custom SAPUI5 application, using WEB IDE, and I have created a custom view, where I need to bind the data, based on parameter received from last view, but page load event is not firing, please review my code and advise,

Manifest.json

"routing": {
            "config": {
                "routerClass": "sap.m.routing.Router",
                "viewType": "XML",
                "viewPath": "oomsdisplay.pso.com.view",
                "controlId": "app",
                "controlAggregation": "pages",
                "bypassed": {
                    "target": [
                        "notFound"
                    ]
                },
                "async": true
            },
            "routes": [
                {
                    "pattern": "",
                    "name": "worklist",
                    "target": [
                        "worklist"
                    ]
                },
                {
                    "pattern": "ZISOHSet/{objectId}",
                    "name": "object",
                    "target": [
                        "object"
                    ]
                },
                {
                    "pattern": "ZISOHSet/{objectId}",
                    "name": "payobject",
                    "target": [
                        "payobject"
                    ]
                }
            ],
            "targets": {
                "worklist": {
                    "viewName": "Worklist",
                    "viewId": "worklist",
                    "viewLevel": 1
                },
                "object": {
                    "viewName": "Object",
                    "viewId": "object",
                    "viewLevel": 2
                },
                "objectNotFound": {
                    "viewName": "ObjectNotFound",
                    "viewId": "objectNotFound"
                },
                "notFound": {
                    "viewName": "NotFound",
                    "viewId": "notFound"
                },
                "payobject": {
                    "viewName": "PayObject",
                    "viewId": "payobject",
                    "viewLevel": 2
                }
            }
        }

here is my C0mponent.js,

init : function () {
            // call the base component's init function
            UIComponent.prototype.init.apply(this, arguments);

            // initialize the error handler with the component
            this._oErrorHandler = new ErrorHandler(this);

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

            // create the views based on the url/hash
            this.getRouter().initialize();
        },

Now, I have created a custom view, when I press the button, on View Object, my second view i.e. PayObject will be called, here is my code on button press of view one,

  fViewPayment : function (oEvent) {
    this.getRouter().navTo("payobject", {
                        objectId: "MyParameterhere"
                });
}

Now, here is my PayObejct view, init event, with object matched, but it is not working,

onInit: function() {
        var iOriginalBusyDelay,
                    oViewModel = new JSONModel({
                        busy: true,
                        delay: 0
                    });
                // Store original busy indicator delay, so it can be restored later on
                iOriginalBusyDelay = this.getView().getBusyIndicatorDelay();
                this.setModel(oViewModel, "objectView");
                this.getOwnerComponent().getModel().metadataLoaded().then(function() {
                    // Restore original busy indicator delay for the object view
                    oViewModel.setProperty("/delay", iOriginalBusyDelay);
                });
                var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
                oRouter.getRoute("payobject").attachPatternMatched(this._onObjectMatched, this);
    }
    // this event is not firing
        _onObjectMatched: function(oEvent) {
    var sObjectId = oEvent.getParameter("arguments").objectId;
    sap.m.MessageBox.show(sObjectId);
// my logic here    
}

thanks,

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Thijs Verkuijlen Feb 18 at 06:27 PM
0

Hi Hamdan,

Can I ask why you use this.getRouter() in here:

fViewPayment : function (oEvent) {
    this.getRouter().navTo("payobject", {
            objectId: "MyParameterhere"
    });
}

And in here you set the oRouter again on the onInit:

onInit: function() {
        var iOriginalBusyDelay,
                    oViewModel = new JSONModel({
                        busy: true,
                        delay: 0
                    });
                // Store original busy indicator delay, so it can be restored later on
                iOriginalBusyDelay = this.getView().getBusyIndicatorDelay();
                this.setModel(oViewModel, "objectView");
                this.getOwnerComponent().getModel().metadataLoaded().then(function() {
                    // Restore original busy indicator delay for the object view
                    oViewModel.setProperty("/delay", iOriginalBusyDelay);
                });
                var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
                oRouter.getRoute("payobject").attachPatternMatched(this._onObjectMatched, this);
    }
    // this event is not firing
        _onObjectMatched: function(oEvent) {
    var sObjectId = oEvent.getParameter("arguments").objectId;
    sap.m.MessageBox.show(sObjectId);
// my logic here    
}

Are you using a BaseController.js in this scenario?

Kind regards,

T.

Share
10 |10000 characters needed characters left characters exceeded