cancel
Showing results for 
Search instead for 
Did you mean: 

Root component id

former_member238473
Discoverer
0 Kudos

Hello,

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?

Thanks

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member238473
Discoverer
0 Kudos

@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

junwu
Active Contributor

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

Comp1

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?

junwu
Active Contributor
0 Kudos

why u need that?

former_member340030
Contributor
0 Kudos
,

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

Thanks

Viplove