Eli
Eli

Reputation: 626

SapUI5: Why getting an error "Cannot read property 'setText' of null" on custom control

I'm trying to extend a MessageStrip control.

For starters, I've created a new file to extend it with no new params at all

MessageStrip.js

sap.ui.define(["sap/m/MessageStrip"],
    function (MessageStrip) {
    "use strict";
    return MessageStrip.extend("com.sap.it.cs.itsdpphome.controller.fragments.MessageStrip", {
        metadata: {
            properties: {
            },
            aggregations: {
            },
            events: {
            }
        },

        init: function () {
        },

        renderer:{}
    });
});

I've created also an xml file that retrieves a data from a model:

<List  items="{msgData>/msgData}" >
<CustomListItem>
    <wt:MessageStrip
        text="{msgData>Text}"
        type="{msgData>Type}"
        showIcon="true"
        showCloseButton="false"
        customIcon="{msgData>customIcon}"
        class="sapUiMediumMarginBottom">
        <Link text="{msgData>linkText}"
            target="{msgData>linkTarget}"
            href="{msgData>linkUrl}" />
    </wt:MessageStrip>
</CustomListItem>
</List>

I can get all model params in xml, except from "text" param!

If I remove text="{msgData>Text}", then it displays all the correct params except from the text.

But when I add the text="{msgData>Text}", then the console displays an error:

Uncaught TypeError: Cannot read property 'setText' of null

enter image description here

Why is that happening?

Upvotes: 0

Views: 3501

Answers (1)

Haojie
Haojie

Reputation: 5713

You have to call init of your base: sap.m.MessageStrip in your own init .

init: function () {
    MessageStrip.prototype.init.call(this);
},

It should solve your problem.

Upvotes: 2

Related Questions