fabiopagoti
fabiopagoti

Reputation: 1541

Is it possible to have XML Fragments IDs prefixed with its view's ID?

When a XML view is declared, all of its controls IDs are prefixed by the ID of the view itself.

UI5 Diagnotic tool showing a XML view

In order to get any control inside the controller it's necessary to use:

this.byId()

... where this points to the controller by default.

I already know that there is

sap.ui.getCore().byId() 

as well which can be used to retrieve a control defined in a JS View or created without a view prefix.

I declared a XML fragment with a dialog and a Text control which will contain a text defined by my controller. I noticed that the ID I defined inside the fragment is not prefixed with the view's ID.

My question is: Is it possible to have XML Fragments IDs prefixed with its view's ID (then I could use this.byId instead of sap.ui.getCore) ?

Upvotes: 1

Views: 816

Answers (1)

Veeraraghavan N
Veeraraghavan N

Reputation: 849

I checked and this appears to be happening only when you are adding the fragment from a controller.
If the fragment is defined in the static time in the xml view the ID's of the content derive their name from the view.
The way to get over this is to ensure your fragment ID is derived from your view. The code would be something like this in your controller.

oPage.addContent(new sap.ui.xmlfragment(this.createId("idFragment"),  "fragmentcreation.SampleFragment"));

IdFragment = ID for your fragment
fragmentcreation.SampleFragment = Name of your fragment(fragmentcreation is the folder)

Upvotes: 2

Related Questions