Binding, Context, ContextBinding and BindingContext in ui5

Thanks, Allen, that really helped. It really mainly was a confusion regarding the documentation and the getValue slipped me as well.

To add another answer to a question only implicitly included in the title:

context binding: the binding you set up to a given path.

binding context: the context of a given binding, i.e. when coming from a component, or some other set up binding.

Cheers Michel


your questions are answered below. Hope it helps.

  1. Now what I do not quite get is: The context binding new sap.ui.model.ContextBinding(oModel, sPath, oContext, mParameters?, oEvents?): takes a path and a context as a parameter. I am assuming that this oContext is not exactly the context described above but some metadata on the binding. is this correct? Or is this the definition of thep ath which the path parameter is relative to?

the oContext is the context you mentioned above, to be precise, is sap.ui.model.Context.

  1. What also seems weird is when you want to create a context itself new sap.ui.model.Context(oModel, sPath, oContext) takes a context again. I believe that this is just an unfortunate naming thing i am looking at, but I am not quite sure.

I guess the documentation here confused you. Actually, sap.ui.model.Context only takes oModel and sPath as parameters. The following code is what i get from sap-ui-core.js. You can see the JSDoc part about parameters is actually inconsistent with the code. Maybe there is some kind of typo there.

    /**
    * Constructor for Context class.
    *
    * @class
    * The Context is a pointer to an object in the model data, which is used to 
    * allow definition of relative bindings, which are resolved relative to the
    * defined object.
    * Context elements are created either by the ListBinding for each list entry
    * or by using createBindingContext.
    *
    * @param {sap.ui.model.Model} oModel the model
    * @param {String} sPath the path
    * @param {Object} oContext the context object
    * @abstract
    * @public
    * @name sap.ui.model.Context
    */
    var Context = sap.ui.base.Object.extend("sap.ui.model.Context", 
    /** @lends sap.ui.model.Context.prototype */  {
    
    constructor : function(oModel, sPath){
    
        sap.ui.base.Object.apply(this);
    
        this.oModel = oModel;
        this.sPath = sPath;
    
    },
    
    metadata : {
        "abstract" : true,
      publicMethods : [
            "getModel", "getPath", "getProperty", "getObject"
        ]
    }
    
    });
  1. From a programming point of view, I do not understand why the following works:
  • create list binding to context via model.bindList() passing a path only.
  • attach change-event handler to binding
  • call get_contexts() on binding
  • receive data in change event handler (and see the oData-property filled in the model).

and there seems to be no way of doing the same for a property binding which i'd assume I can generate via model.bindProperty(). I can generate the binding, but the binding I receive seems to have no handle to actually fetch data.

Actually you can also attachChange event to sap.ui.model.PropertyBinding, and you can call getValue() to get the data.

Tags:

Sapui5