Search code examples
sapui5

Is there a way to make the model name of SAPUI5 bindings in fragments dynamic?


I have a SAPUI5 JS fragment that will be used with different models. That means I have some coding like this (of course quite bigger and not just one button):

sap.ui.jsfragment("com.domain.FragmentName", {
    createContent: function (oController) {
        var oBindingBase= oController.getBindingInfo();
        return [
           new sap.m.Button({text : oBindingBase.modelName + ">" +
                                   oBindingBase.context + "Something",
        ];
    }
});

With this "hack" I am able to reuse the fragment multiple times. Regardless if there is a called model or the path changes.

I know it would be possible to set the binding object in the controller by using the path. But as I know the model name must be defined in the binding itself in any case.

Is there a way to do the described thing by using XML views?


Solution

  • Looks like there is no way to reach the same behaviour wiht SAPUI5 XML views. The only solution would be to build an intermediate (local) model that has always the same model name but will be filled form different other models.

    The drawback: A two way binding would not be possible to the real underlying model.