SAP UI5应用如果遇到数据绑定问题时,应该如何自己定位问题?

简介: I will use the field “ClosingDate” to demonstrate my favorite approach to trouble shoot field binding issue. Generally speaking, the issue could be summarized as that although you have bound your UI control to a given field of a Json or odata model, however in the runtime nothing is displayed in the

I will use the field “ClosingDate” to demonstrate my favorite approach to trouble shoot field binding issue. Generally speaking, the issue could be summarized as that although you have bound your UI control to a given field of a Json or odata model, however in the runtime nothing is displayed in the control.


In order to find the root cause of such issue, we need to understand the logic that how is the field value in a model bound to our control and finally displayed in the UI.


image.png


The field above, “Closing Date”, is bound to the model field “ClosingDate” in the xml view.


image.png


In the runtime, such binding relationship will be represented by an instance of Binding.


image.png


The corresponding js file for each kind of property binding could be found from this folder:


image.png


Within this folder, you can find dedicated js file for OData Model property, Json Model property and i18n Model property accordingly.

The Binding and ClientPropertyBinding are the prototype of these concrete binding type.


image.png


Since there are so many controls which have been bound to model fields, the constructor of Binding will be called again and again for each binding relationship.


As I am only interested with “ClosingDate”, so I make small modifications on the Binding.js directly in Chrome.


Then I resume the execution of debugger and soon the debugger stops at the very point where the mapping instance for “ClosingDate” is instantiated:


image.png


Every binding instance has one attribute sPath to indicate which model field it represents, and another attribute oValue, which contains the actual content of the model field, which will be rendered in the control.


Now I would like to know for the model field “ClosingDate”, when the oValue will be filled and where the content of oValue come from. So I switched to the inner callstack:


image.png


The value will be filled by this._getValue():


image.png


And now we are clear: the oValue of current binding instance comes from the corresponding node of OData model, to be exactly using UI5 terminology, from the binding Context.


image.png


The OData Model instance has one attribute “oData” which contains detail data for each list item. ODataModel._getObject will get the binding context of current binding property instance and then fetch the property value from that binding context:


image.png



Now this.oValue is filled and this very value will be displayed inUI.


image.png


When the control containing any attributes which are bound to a property of Model, the function “getExternalValue” of related property binding instance will be called. The result will be displayed in UI.


If there is any formatter defined for the property binding by application, for example in my application I have defined my custom formatter “dateFormatterMaster”. In line 79 framework will call such formatter if there is any.


image.png


And through debugging and callstack, I can see my formatter is called.


image.png

相关文章
|
前端开发 JavaScript 小程序
|
6月前
|
XML JavaScript 前端开发
SAP UI5 的数据绑定语法概述
SAP UI5 的数据绑定语法概述
34 0
|
5月前
|
开发者
SAP UI5 控件双向数据绑定后显示数据出问题,可以调试这个方法
SAP UI5 控件双向数据绑定后显示数据出问题,可以调试这个方法
28 0
|
6月前
|
Web App开发 开发者
SAP UI5 应用开发教程之四十二 - SAP UI5 自带的 Diagnostics 诊断工具使用方法介绍
SAP UI5 应用开发教程之四十二 - SAP UI5 自带的 Diagnostics 诊断工具使用方法介绍
25 0
|
6月前
|
Web App开发 开发者
SAP UI5 应用开发教程之三十九 - SAP UI5 应用出现白屏的一些常见错误和分析方法分享试读版
SAP UI5 应用开发教程之三十九 - SAP UI5 应用出现白屏的一些常见错误和分析方法分享试读版
28 0
|
6月前
|
开发者
SAP UI5 初学者教程之十九 - SAP UI5 数据类型和复杂的数据绑定
SAP UI5 初学者教程之十九 - SAP UI5 数据类型和复杂的数据绑定
39 0
|
7月前
|
JSON 数据格式
通过一个具体的例子,深入了解 SAP UI5 控件数据双向绑定的工作原理和问题排查方法试读版
通过一个具体的例子,深入了解 SAP UI5 控件数据双向绑定的工作原理和问题排查方法试读版
31 0
|
7月前
|
Web App开发 前端开发 JavaScript
SAP UI5 应用开发教程之八十二 - 采用 OPA5 开发支持页面跳转的 SAP UI5 集成测试用例试读版
SAP UI5 应用开发教程之八十二 - 采用 OPA5 开发支持页面跳转的 SAP UI5 集成测试用例试读版
37 0
|
JSON JavaScript 数据格式
SAP UI5应用如果遇到数据绑定问题时,应该如何自己定位问题?
SAP UI5应用如果遇到数据绑定问题时,应该如何自己定位问题?
SAP UI5应用如果遇到数据绑定问题时,应该如何自己定位问题?
|
存储 XML Web App开发
深入学习SAP UI5框架代码系列之四:SAP UI5控件的元数据实现
深入学习SAP UI5框架代码系列之四:SAP UI5控件的元数据实现
154 0
深入学习SAP UI5框架代码系列之四:SAP UI5控件的元数据实现