0

I have a NavContainer and I want to set the pages with a JSONModel via aggregation binding. In the end the NavContainer should contain a bunch of XMLViews with given id's (to navigate to them later) and the viewNames to load the views.

<NavContainer id="idNavContainer" height="16em" initialPage="{/oInitialStep/sId}" pages="{/aStepPages}">
  <mvc:XMLView id="{sId}" viewName="{sViewName}" />
</NavContainer>

This is the structure of the JSONModel:

{
    oInitialStep: {
       sId: "idInitialStep",
       sViewName: "my.app.views.init"
    },
    aStepPages: [
     {
       sId: "idInitialStep",
       sViewName: "my.app.views.init"
     },
     {
       sId: "idStep2",
       sViewName: "my.app.views.step2"
     },
     {
       sId: "idLastStep",
       sViewName: "my.app.views.last"
     },
   ]
}

Unfortunately, I get this error:

Error: "__xmlview1--{sId}" is not a valid ID.

I tried replacing the NavContainer with a simple list, copying it from the documentation, and the same error occured. It seems like it is generally not possible to bind the id using an aggregation. Is that correct and does anyone know a work-arround?

Furthermore, the binding of the initialPage of the NavContainer does not work. It seems to be the same problem doesn't it?

IceRevenge
  • 1,451
  • 18
  • 33

1 Answers1

-1

I found a way to do it by creating the pages in a factory function but I'd still like to know if it is possible using a template in the XML.

In the XMLView:

<NavContainer pages="{ path: '/aStepPages', factory: '.manufactureNavContainerPages'}" />

In the controller:

manufactureNavContainerPages: function(sId, oContext) {
  return new sap.ui.core.mvc.XMLView(
    oContext.getProperty("sId"), 
    {
      viewName: oContext.getProperty("sViewName")
    }
  );
}
IceRevenge
  • 1,451
  • 18
  • 33
  • This approach is relying heavily on synchronous XHRs which freezes browser's UI-/ main-thread during the requests. And according to the [API reference](https://openui5.hana.ondemand.com/api/sap.ui.core.mvc.View#constructor), "applications should **not** call the constructor directly, but use one of the view factories instead, e.g. `(XML)View.create`". I'm afraid the approach dynamically creating views via a JSONModel needs to be re-evaluated. – Boghyon Hoffmann Aug 12 '20 at 13:23
  • @BoghyonHoffmann I guess that has helped me too. Then I'll just define the XMLViews in the NavContainer with XML. – IceRevenge Aug 12 '20 at 15:03
  • Also if you embed a view declaratively, make sure to add `async="true"`: https://stackoverflow.com/a/63344834/5846045 – Boghyon Hoffmann Aug 12 '20 at 16:34