Question

I am trying to add an htmlview (which is using declarative support according to SAP's docs) to an index page that is also using declarative support. Using data-sap-ui-type="ui.MyView" makes me to ask two questions:

  • Is there any equivalent to sap.ui.localResources in declarative support?
  • data-ui-type is not adding the view.html suffix to the view that should be laoded. Is there a special pattern for MVC in declarative support or is there currently no way to implement it?

Kind regards, Nico

Was it helpful?

Solution

find some basic samples here: https://openui5.hana.ondemand.com/#docs/guide/MVC.html

First of all I believe that you always have to set sap.ui.localResources in code.

As you can see instanciating a HTMLView from an HTMLView goes like this:

<div data-sap-ui-type="sap.ui.core.mvc.HTMLView" id="MyHTMLView" data-view-name="example.mvc.test2"></div>

This will load example.mvc.test2.view.html and place it into your parent view.

Generally speaking the JS API translates into HTMLViews like this:

new sap.ui.AnyControl("myId", {
  aLittleProperty: "10",
  property: false,

  press: functionInMyController,
  morePress: a.static.myFunction,

  defaultAggregation: [ 
     new sap.ui.OtherControl("otherId1"),
     new sap.ui.OtherControl("otherId2")
  ],
  anotherAggregation: new sap.ui.OtherControl("otherId3")
}).addStyleClass("myClass");

<div data-sap-ui-type="sap.ui.AnyControl" 
     id="myId" 
     class="myClass"

     data-a-little-property="10",
     data-property="false"

     data-press="functionInMyController"
     data-more-press="a.static.myFunction">

     <div data-sap-ui-type="sap.ui.OtherControl" id="otherId1"></div>
     <div data-sap-ui-type="sap.ui.OtherControl" id="otherId2"></div>

     <div data-sap-ui-aggregation="anotherAggregation">
         <div data-sap-ui-type="sap.ui.OtherControl" id="otherId3"></div>
     </div>

</div>

Note that:

  • The id and CSS classes are set with the regular HTML attributes
  • Property names translate from camelCase to lower-case separated with "-" (due to the fact that HTML is not case-sensitive)
  • No matter what type the property is you of course have to put it in quotes in HTML
  • Whatever you put directly inside a HTML-defined control is considered to belong into it's default aggregation

BR Chris

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top