To instantiate an XML view, SAPUI5 provides the factory method create in the class sap.ui.core.mvc.XMLView. In the example shown in the figure Instantiating an XML View, the module in which the XML view is created is therefore dependent on the sap/ui/core/mvc/XMLView module.
The create method is passed an object with the required configuration options. A complete list of all available options can be found in the API Reference in the Demo Kit.
In the example shown, the following two properties are used:
id
The id property can be used to specify an Id for the view instance. If the id property is not passed, an Id will be generated by SAPUI5.
viewName
The viewName property is used to pass the name of the XML view to be loaded (see above). As discussed, the file suffix .view.xml is automatically added by SAPUI5.
The create method loads views asynchronously via the module system. The advantage of asynchronous loading over synchronous loading is that the UI does not freeze for the duration of the loading process and the functionalities are not blocked during view initialization.
Since the loading process is asynchronous, the create method does not return the view instance itself, but a Promise that resolves with the view instance.
Therefore, on the returned Promise, as shown in the example, call the then method to register a callback function for the success case. This function is called as soon as the view instance is available, and the instance is passed to it via the interface (oView).
In the implementation of the callback function, the view instance can be added to a UI area by calling the placeAt method.