How to get a specific EntitySet dynamically in an UI5 XML-View?

1.3k Views Asked by At

Is there a way to pass a dynamic parameter to identify a specific EntitySet in a UI5 XML-View? I am using UI5 with ODataV2 and here is my XML of an UI5 Text Object:

<Tex text="{/ProductSet('AR')/ProductName}"/>

Note that the 'AR' is the Key of a specific EntitySet, it gives me the ProductName from a specific ProductSet.

But instead of hardcoding the Key, is there a way to pass it dynamically? Something like this for example:

<Tex text="{/ProductSet('{ProductKey}')/ProductName}"/> 


                        
2

There are 2 best solutions below

0
On BEST ANSWER

You should use Property Binding or Element Binding from the controller. Here you can compose any path you like.

0
On

So I resolved this Issue by preloading the EntitySet I need in the controller. I don´t know if it is the best way, but it works as desired. I preload the ProductSet in the "onBeforeRendering" -method of my Controller, so the Data will be already available when the other async Calls of the View are made.

onBeforeRendering:function(){           
    this.loadProductSet();  
    },

    

    loadProductSet: function () {
        return new Promise(function (resolve, reject) {
            this.getView().getModel().read("/ProductSet", {
                success: function (oData) {
                    resolve();
                }.bind(this),
                error: function (oError) {
                    reject();
                }.bind(this)

            });
        }.bind(this));

    },

And in the XML View I use formatter to pass the ID of the specific Set:

<ObjectAttribute  title="Name" text= "{parts :['ProductKey'], formatter: '.formatter.getProductSet' }" />

And here the formatter code:

getProductSet: function (sProductKey) {
        var oModel = this.getView().getModel();
        var sProductName = oModel.getProperty("/ProductSet('" + sProductKey + "')/ProductName");
        return sProductName;
    }

But it would still be very nice, if there was a way to pass a parameter dynamically in the XML :) Hope some day it will be implemented.