cancel
Showing results for 
Search instead for 
Did you mean: 

getCore().byId() not working

shashidhar_peddi
Explorer
0 Kudos

Hi Experts,

What is the difference between this.getView().byId("id123") and sap.ui.getCore().byId("id123")?

Please see the following JS bin:

http://jsbin.com/facokikilo/edit?html,output

I am trying to get the reference of the two buttons and set their button type dynamically, but the getCore().byId() method is failing to return the reference of the buttons.

Could you check and let me know how to resolve this issue.

Regards,

Shashidhar

Accepted Solutions (1)

Accepted Solutions (1)

former_member182372
Active Contributor
0 Kudos

code worth 1000s words:

View.prototype.byId = function(sId) {

  return sap.ui.getCore().byId(this.createId(sId));

};

View.prototype.createId = function(sId) {

  if (!this.isPrefixedId(sId)) {

  sId = this.getId() + "--" + sId;

  }

  return sId;

};

shashidhar_peddi
Explorer
0 Kudos

Hi Maksim,

Where can I find this code? How did you locate it?

Regards,

Shashi

former_member182372
Active Contributor
0 Kudos

resources\sap\ui\core\mvc\View-dbg.js

i just knew it is there, learned years ago LOL

Answers (1)

Answers (1)

saivellanki
Active Contributor
0 Kudos

Hi Shashidhar,

this.getView() refers to your view associated to the controller.

sap.ui.getCore() refers to the core component which is available throughout the application. 

In your case, this.getView().byId("idButton2") works. JS Bin - Collaborative JavaScript Debugging

But, if you want to get through core, then view id suffix needs to be added, something like sap.ui.getCore().byId("__xmlview0--idButton2") . JS Bin - Collaborative JavaScript Debugging

Regards,

Sai Vellanki.