Skip to Content

sap.ui.commons.Label - getText() returns empty string

Hi experts,

I have a label which is bound to a JSON Model:

var oModel1 = new sap.ui.model.json.JSONModel(data1);

var tokenText = new sap.ui.commons.Label({
text : "{/LoginResult/SessionToken}"
});

tokenText.setModel(oModel1);

alert(tokenText.getText());

The binding is working, the label is showing the token from the JSON Model. The label is placed in the content of the view.

However, the getText()-function of the Label is returning only an empty string.

Any ideas what might be wrong here? It's like the data binding is not actually done until the view is rendered or something like that?

Br

Max

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Apr 28, 2014 at 11:55 AM

    can you try ,

     
    1. var oModel1 = new sap.ui.model.json.JSONModel(data1).attachRequestCompleted(function(){
    2. var tokenText = new sap.ui.commons.Label({
    3. text : "{/LoginResult/SessionToken}"
    4. });
    5. tokenText.setModel(oModel1);
    6. alert(tokenText.getText());
    7. });


    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Apr 28, 2014 at 10:14 AM
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Apr 29, 2014 at 05:59 PM

    Interesting thread. Can you post the json model itself here? Is it from a local file or variable defined inline?

    new sap.ui.model.json.JSONModel(data1);

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 08, 2014 at 05:19 AM

    Any ideas what might be wrong here? It's like the data binding is not actually done until the view is rendered or something like that?

    This is exactly right. The onInit() method of the controller is invoked after the view has completed creating the Control Tree / DOM.

    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.