I have been pondering the internals of and relationship between context, contextbinding, and bindingcontext for a few days now and i am not sure whether there is a major misconception on my side. Maybe some of you can help me sort it out. I am putting my assumptions below. I might want to say first that I always work with oData models here.
This is what I believe to understand reading the documentation:
A context is a reference to a data object in a model.
A binding is basically an event provider which (in case of a one way binding) observes the status of a specific context and emits events when it is changed/data loaded ... and therefore allows for registering event handlers for events on that specific context. In terms of programming objects, there are property bindings and list bindings (is this true - or is list binding all that is ever relevant?).
At any rate, my understanding is that a list binding is the model-side of a component's aggregation binding, while a property binding is called property binding both from a component's and a model's point of view (confusing?).
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?
What also seems weird is when you want to create a context itself new sap.ui.model.Contextabov(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.
Then there is contextbinding and bindingcontext. I'd assume that contextBinding is the binding to a specific context as described e. And a bindingcontext is the meta data regarding a context- or list binding.
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.
I hope the ramble explains my problem. In case you ask : what do you want to do? I actually do not want to do anything with it, I just do not quite understand how this works. Binding to ui controls and so forth works just fine, but I'd prefer to really understand what is underneath the hood. I have been reading debug files and unit tests a bit, but discussing it with you guys seems a great way as well.
If this is unclear I'll happily add anything that helps.
Cheers Michel