Skip to Content

sap.ui.getCore() --> byId() or getElementById()?

Hi, what is the better way to access a View-Control from the Controller by its ID:

sap.ui.getCore().byId() or sap.ui.getCore().getElementById()?

Where is the difference?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Posted on Dec 09, 2014 at 02:58 PM

    If you're in the controller, you shouldn't use neither of them (for the most part).

    Use byId of the controller. It will resolve the generated id prefixes automatically.

    - Max

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 10, 2014 at 12:57 AM

    Hi Michael,

    I think its best to avoid calling the .byId() function via sap.ui.getCore() as much as possible and rather call it via the object its created under. such as oController.byId("idButton"); or this.byId("idButton") or oView.byId("idButton");

    See this section on Unique Id's in UI5 Developers Guide:

    SAPUI5 SDK - Developers Guide - Support for Unique ID's

    Cheers,

    Brad

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 09, 2014 at 02:38 PM

    Both are the same & getElementByID() is deprecated. So, its better to use byId().

    JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.ui.core.Core

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.