Show TOC

Programmatically Instantiating XML FragmentsLocate this document in the navigation structure

For each fragment type, SAPUI5 provides a method that can be used to programmatically instantiate a fragment.


To give an example of a programmatic instantiation of a XML fragment, you first have to define one. The following code presents an example definition:

<Button xmlns= "sap.ui.commons" id= "btnInFragment" text= "Hello World" />

This fragment can be instantiated from a controller as follows:

var myButton = sap.ui.xmlfragment( "my.useful.VerySimpleUiPart" ); 
		// this specific fragment does not need a controller

Fragments can be instantiated from JSViews, as well. Fragments of any type can be used within views of any type.