If a fragment with a control ID is instantiated twice without giving an ID, a duplicate
ID error occurs.
Given the following XML fragment
<Button text="Hello World" />
<Button id="btnInFragment" text="Hello World" />
first button will always have a generated ID, as, for instance,
. 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
case the fragment is instantiated giving the ID myFragment
. You should
not rely on the exact syntax of this prefixing.
// Button ID will get prefixed by "myFragment"