Show TOC

IDs in Declarative XML or HTML FragmentsLocate this document in the navigation structure

If a fragment with a control ID is instantiated twice without giving an ID, a duplicate ID error occurs.

Given the following XML fragment example:
<HorizontalLayout xmlns="sap.ui.commons">
   <Button                    text="Hello World" />
   <Button id="btnInFragment" text="Hello World" />
</HorizontalLayout>
The first button will always have a generated ID, as, for instance, __button2. This is regardless of how the fragment is instantiated or whether it resides inside a view.
The second button will either have the ID btnInFragment, in case the fragment is instantiated without giving an ID. This approach is easy to use, but implies the risk of ID collisions when instantiated multiple times:
sap.ui.htmlfragment("my.useful.UiPartZ"); // Button ID will not be prefixed
The other possible ID of the second button is myFragment--btnInFragment, in case the fragment is instantiated giving the ID myFragment. You should not rely on the exact syntax of this prefixing.
sap.ui.htmlfragment("myFragment", "my.useful.UiPartZ"); 
// Button ID will get prefixed by "myFragment"