SAPUI5 routing throws error “Control (ID of an App control) could not be found”

Tina Chen picture Tina Chen · Aug 26, 2016 · Viewed 10.8k times · Source

This question derived from this answer (I can't get the source code running) , My requirement is similar with this question, which is a page with app control, navigate to a SplitContainer with one master and one detail view. Master.view.xml is loaded successfully, But I get

"Control with ID app could not be found"

error when I click item.

my metadata.json:

"routing": {
  "config": {
    "routerClass": "cts.alert.MyRouter",
    "viewType": "XML",
    "viewPath": "cts.alert.view",
    "controlId": "app",
    "controlAggregation": "pages",
    "clearTarget": "false",
    "bypassed": {
      "target": [
        "notFound"
      ]
    },
    "async": true
  },
  "routes": [
    {
      "pattern": "",
      "name": "worklist",
      "target": [
        "worklist"
      ]
    },
    {
      "pattern": "split",
      "name": "split",
      //<SplitContainer id="idAppControl"> in SplitApp.view.xml
      "view": "SplitApp",
      //<App id="app"/> in App.view.xml
      "targetControl": "app",
      "subroutes": [
        {
          "pattern": "master",
          "name": "main",
          "view": "Master",
          "targetAggregation": "masterPages",
          "targetControl": "idAppControl", //SplitContainer id
          "subroutes": [
            {
              "pattern": "VEHICLES/{objectId}",
              "name": "object",
              "view": "Detail",
              "targetAggregation": "detailPages",
            }
          ]
        }
      ]
    },
    {
      "name": "catchallMaster",
      "view": "Master",
      "targetAggregation": "masterPages",
      "targetControl": "idAppControl",
      "subroutes": [
        {
          "pattern": ":all*:",
          "name": "catchallDetail",
          "view": "NotFound"
        }
      ]
    }
  ],
  "targets": {
    "master": {
      "viewName": "Master",
      "viewLevel": 2,
      "viewId": "master",
      "controlAggregation": "masterPages"
    },
    "worklist": {
      "viewName": "Worklist",
      "viewId": "worklist",
      "viewLevel": 1
    },
    "object": {
      "viewName": "Detail",
      "viewId": "detail",
      "viewLevel": 3
    },
    "objectNotFound": {
      "viewName": "ObjectNotFound",
      "viewId": "objectNotFound"
    },
    "notFound": {
      "viewName": "NotFound",
      "viewId": "notFound"
    },
    "detailObjectNotFound": {
      "viewName": "DetailObjectNotFound",
      "viewId": "detailObjectNotFound"
    },
    "detailNoObjectsAvailable": {
      "viewName": "DetailNoObjectsAvailable",
      "viewId": "detailNoObjectsAvailable"
    }
  }
}

I am not sure if subroutes still need so many targets. And I know the problem lies in "targetControl" : "app" in "split" route , but if I add "targetControl" : "idAppControl" in "object" route , it will also produce

Control with ID idAppControl could not be found

And this answer said:

You can't join the same control as your parent route has.

I am really confused now .

And I also tried delete "rootview" in "sap.ui5" , not working.

Any help will be welcomed! Thanks in advance!

Answer

Tina Chen picture Tina Chen · Aug 27, 2016

Thanks to this route configuration doc, I solved my problem.

I thought it is"targetControl": "app" in the split route that caused this error, but actually it is because "controlId": "app" in routing.config that caused this problem.

The config parameter defines the default values for route configuration.

After change that, I got another error:

The target worklist has no controlId set and no parent so the target cannot be displayed.

So I deleted target in worklist route and added targetControl: app in it, since it no longer have a default targetControl value.

Here is the new route configuration:

"routing": {
    "config": {
        "routerClass": "cts.alert.MyRouter",
        "viewType": "XML",
        "viewPath": "cts.alert.view",
        "controlAggregation": "pages",
        "clearTarget": "false",
        "bypassed": {
            "target": [
                "notFound"
            ]
        },
        "async": true
    },
    "routes": [
        {
            "pattern": "",
            "name": "worklist",
            "view": "Worklist",
            "targetControl": "app"
        },
        {
            "pattern": "split",
            "name": "split",
            "view": "SplitApp",
            "targetControl": "app",
            "subroutes": [
                {
                    "pattern": "master",
                    "name": "main",
                    "view": "Master",
                    "targetAggregation": "masterPages",
                    "targetControl": "idAppControl",
                    "subroutes": [
                        {
                            "pattern": "VEHICLES/{objectId}",
                            "name": "object",
                            "view": "Detail",
                            "targetAggregation": "detailPages"
                        }
                    ]
                }
            ]
        },
        {
            "name": "catchallMaster",
            "view": "Master",
            "targetAggregation": "masterPages",
            "targetControl": "idAppControl",
            "subroutes": [
                {
                    "pattern": ":all*:",
                    "name": "catchallDetail",
                    "view": "NotFound"
                }
            ]
        }
    ],
}