cancel
Showing results for 
Search instead for 
Did you mean: 

OData model defined in manifest.json 'comes' after rendering the target view - not on init.

0 Kudos

The question is about Router and the process of creation of a "target" view in async mode.

Controller of a root view (rootView) is able to wait for the metadata in onInit function:

onInit: function() {
  var model = this.getView().getModel();      model.metadataLoaded().then( function() {          //.. ok!

However this is not possible in any other controller of a target view (even if I make a root view as a target). Model like this.getView().getModel() comes after rendering of a target and not on init.

If I check network tab the sequence is:

  1. root view
  2. target view
  3. root controller (model is defined in onInit)
  4. target controller (model is undefined in onInit)
  5. model

My questions are:

  1. Is it possible to have model defined in manifest in onInit of a target?
  2. If not what is the recommended solution? To create one from the service? Still the model will be overwritten after render?
  3. I am messing something with async mode?

If you check most of documentation and tutorials there is no async mode in manifest, or there is no such an issue. My main configuration below (notice async is true):

		"rootView": {
			"viewName": "my.path.view.App",
			"type": "XML",
			"async": true,
			"id": "app"
		},

                 ...
                "dataSource": "MY_SRV",
		"preload": true
                ...
                "routing": {
			"config": {
				"routerClass": "sap.m.routing.Router",
				"viewType": "XML",
				"async": true,
				"viewPath": "my.path.view",
				"controlAggregation": "pages",
				"controlId": "app",
				"transition": "slide",
				"viewLevel": 1
			},
			"routes": [{
				"pattern": "",
				"name": "master",
				"target": "master"
			}, {
				"pattern": "/{ID}",
				"name": "product",
				"target": "product"
			}],
			"targets": {
				"master": {
					"viewName": "Master",
					"viewId": "master",
					"viewLevel": 1,
					"clearControlAggregation": true
				},
				"product": {
					"viewName": "Product",
					"viewLevel": 2,
					"clearControlAggregation": true
				}
			}
		}

Accepted Solutions (1)

Accepted Solutions (1)

junwu
Active Contributor
0 Kudos

in init, you have to use this.getOwnerComponet().getModel

Answers (0)