0

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}"/> 


                        
Wpe
  • 23
  • 1
  • 5
  • ODataPropertyBinding doesn't send any requests anyway (unlike ODataContextBinding and ODataListBinding). I.e. even if the keys could be dynamically created in XML, the `text` property wouldn't be resolved since there is no request. If there was a corresponding request before, then I don't see the need to define an absolute path in XML. You could just bind an existing context to the Text control and assign `text="{ProductName}"` relatively. – Boghyon Hoffmann Feb 01 '21 at 17:47
  • Thank you Boghyon, i resolved it with preloading the data in the controller. – Wpe Feb 02 '21 at 08:27
  • Would be nice if you could add an answer below (with some more information how exactly you did it) and accept it to let others know that the issue is resolved. If you did it with element binding in the controller as A.vH suggested, consider accepting his answer instead. – Boghyon Hoffmann Feb 02 '21 at 09:22

2 Answers2

0

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

A.vH
  • 881
  • 6
  • 10
0

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.

Wpe
  • 23
  • 1
  • 5