Skip to Content

Root component id

Jan 18, 2017 at 08:47 AM


avatar image
Former Member


I want stable Id's and therefore provide an id to the root control of my application, but I can't figure out, where I can set it. Currently it is automatically generated with the value '__component0'. Does anyone know, where I can set it?


10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Jun Wu Jan 18, 2017 at 01:44 PM

why u need that?

10 |10000 characters needed characters left characters exceeded
VIPLOVE KHUSHALANI Jan 18, 2017 at 01:39 PM

Hi Denis,

You need to set the ID in index.html file.

When you create a html project using webIde , it creates a component (UI component) wrapped inside component container which is placed using placeAt() method on the HTML body. UI component only renders our page.

Below is the code which does this (you will find this code in index.html file between script tags):

sap.ui.getCore().attachInit(function() { new sap.m.Shell({ app: new sap.ui.core.ComponentContainer({ height : "100%", name : "sample" }) }).placeAt("content"); });

Above code instantiate the UI component inside the component container constructor only so here you will not able to set the Id.

So to provide the component Id you need to first create the component with the required ID and than assign it to component container. Like below :

sap.ui.getCore().attachInit(function() {

var oComp = sap.ui.getCore().createComponent({

name: "sample",

id: "Comp1" });

var oCompCont = new sap.ui.core.ComponentContainer("CompCont1",

{ component: oComp });

new sap.m.Shell({

app: oCompCont

}).placeAt("content"); });

so Comp1 will be the id of the component and CompCont1 will be the ID for the component container



10 |10000 characters needed characters left characters exceeded
avatar image
Former Member
Jan 20, 2017 at 08:41 AM

@Jun Wu:

I have some Controllers which deal with DOM Elements by id. With stable ids I can safely access them since there are no unexpected ids that are generated by the UI5

@Viplove Khushalani:

Thanks, that worked very well.

Best regards

Show 1 Share
10 |10000 characters needed characters left characters exceeded

not good idea. if you check the generated html, it will has the exact id


you will easily have duplicate id issue.

in your controller, this.getOwnerComponent will give u the component, from there, you can get id, why you need a hardcoded id?