`
JerryWang_SAP
  • 浏览: 1068666 次
  • 性别: Icon_minigender_1
  • 来自: 成都
文章分类
社区版块
存档分类
最新评论
阅读更多

Recently I am following the exercise Building SAP Fiori-like UIs with SAPUI5( it is really a fantastic guide

 

 

) and I meet with trouble in EXERCISE 3 – FORMATTER. I just copy the source code from the guide:

 

 

Unfortunately my formatter statusText which is used to format LifecycleStatus in Master page is not called in runtime at all:

 

 

And to my surprise,the same syntax for date formatter can work perfectly in detail page. Why?

 

 

Why the formatter for status is not called at all

Since none of other SCNers has complained about this issue, so I assume there must be something wrong in my own code. So I began to debug to compare why formatter for CreatedAt works.

Soon I found out how formatter for CreatedAt works. In the runtime, firstly the raw value of field CreatedAt is fetched from line 22833 and stored in variable oValue, and then passed to its formatter in line 22838.

The “this.fnFormatter” actually points to the formatter scn_exercise.util.Formatter.date defined in my code.

 

 

However, for the failure case,the framework didn’t recognize any formatter for LifecycleStatus,so my formatter is not called at all.

 

 

How does framework parse xml view to get metadata such as formatter information

The screenshot below contains a good entry point for xml view parse debugging.The XMLTemplateProcessor-dbg.js contains the implementation to parse xml source code and create UI5 control accordingly.

 

 

from the callstack we know its method handleChildren, createControls etc is recursively called to handle with controls defined hierarchically in your xml view.

 

 

Finally I reached the code below. After line 21082 is executed, the formatter for field CreatedAt will be parsed.

 

 

I will explain how the reference pointing to my formatter for CreatedAt is parsed via text. before the for loop, variable oObject points to the global window object, since no context exists in this case.

The first for loop: i = 0, execute line 15162, aNames[0] = “scn_exercise”, so after that oObject now points to window.scn_exercise. The secondfor loop: i = 1, aNames[1] = util, so after line 15162 oObject points to window.scn_exercise.util.

The third loop: i = 2, aNames[2] = Formatter, so after line 15162 oObject points to window.scn_exercise.util.Formatter The fourth loop: i = 3, aNames[3] = date, so after line 15162 oObject points to window.scn_exercise.util.Formatter.date.Then quit for loop.

 

 

why the formatter for Lifecyclestatus is failed to be parsed?

based on the previous analysis on formatter for CreatedAt, we can easily figure out what is wrong.

In the case for Lifecyclestatus,there is no attribute named “util” under window.scn_exercise, instead only a dummy one “Component”.

 

 

just compare the correct case for CreatedAt,where all our formatters are existing under window.scn_exercise.

 

 

When the attribute util become available under window.scn_exercise

Since I have defined the usage of formatter implementation in detail view’s controller: jQuery.sap.require(“scn_exercise.util.Formatter”);

the js file will be downloaded via AJAX and execModule is called on it after a successful download:

 

 

the js source code is executed via eval:

 

 

after that the util is available in window.scn_exercise:

 

 

then finally I find the root cause: I forget to add the following line in my master controller. Once I have added this, the issue is gone.

 

 

Hope this blog can give you some hint to do trouble shooting by yourself when you meet with the formatter or xml view parse issue.

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

0
3
分享到:
评论

相关推荐

    sap.training.exc12.formatter_filter_sorter

    在JavaScript编程领域中,"sap.training.exc12.formatter_filter_sorter"可能是一个关于SAP UI5应用开发的练习或教程,重点在于使用JavaScript来处理数据格式化、过滤和排序。SAP UI5是一个用于构建企业级Web应用...

    codeFormatter

    接下来,我们将深入探讨codeFormatter的工作原理、功能特性以及如何在实际项目中有效应用。 一、codeFormatter简介 codeFormatter主要针对编程语言如Java、Python、C++等进行代码格式化,通过预设或自定义的编码...

    JSON Formatter.zip

    下面将详细介绍这款插件的功能、工作原理以及如何配置和使用。 1. **JSON格式化功能** JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,广泛应用于Web服务和API交互。JSON Formatter插件的主要...

    EclipseFormatter.zip

    Eclipse Code Formatter 可直接导入使用,直接下载。为解决网络问题。源码地址:https://github.com/alibaba/p3c/tree/master/p3c-formatter

    jsFormatter

    而对于经验丰富的开发者,这个工具则可以极大地提升他们的工作效率,减少因手动格式化代码而花费的时间。 在处理大型项目或多人合作的工程时,**jsFormatter**的重要性更为突出。通过统一代码风格,可以避免因为...

    Eclipse Formatter 模板 Formatter.xml

    Formatter模板设置好后,保存时可自动格式化代码。代码的空格处理,写的时候不用再担心格式问题。设置保存时,仅保存编辑的行,这样不会更新其他行的代码,提交代码时,也是只变更自己编辑的行。

    exam_formatter_2_setup.exe

    exam formatter 是个不错的工具

    jsFormatter.js + htmlFormatter.js +

    5. **cssFormatter.js**: 这个文件是CSS(层叠样式表)的格式化器,它的功能与jsFormatter.js类似,但专注于CSS代码的格式化。它可以整理选择器、属性和值的排列,增加缩进,以及处理注释等,帮助开发者保持CSS代码...

    Laravel开发-laravel-formatter

    总的来说,Laravel-formatter是一个实用的工具,它扩展了Laravel框架的能力,使得数据格式化工作变得更加简单和高效。无论是处理内部数据还是与外部系统交互,它都能成为开发者得力的助手。在Laravel开发中,了解并...

    eclipseformatter格式化文件

    5. **注释**:单行注释和多行注释的样式,例如是否在注释后添加空行。 6. **导入顺序**:自动排序和压缩import语句,避免冗余导入。 7. **成员排序**:类中成员变量和方法的排序规则。 为了确保团队一致性,开发者...

    jsonFormatter.rar

    通过这个工具,开发者可以清晰地看到JSON对象中的键值对关系,以及嵌套数组和对象的层次结构,从而提高工作效率,减少错误。 这个工具是作为Windows可执行文件发布的,意味着它可以在Windows操作系统上直接运行,...

    java eclipse code formatter

    Java Eclipse Code Formatter是一款用于统一Java代码风格的强大工具,它整合在Eclipse集成开发环境中,能够帮助开发者按照预设的编码规范自动格式化代码,提升代码的可读性和团队协作效率。"Code Style"和"Code ...

    EclipseFormatter 20.9 适配IDEA

    这可能是由于IDEA的新版本与EclipseFormatter的旧版本之间存在不匹配,或者是EclipseFormatter的配置文件需要特定的设置才能在IDEA中正常工作。解决这个问题通常需要以下步骤: 1. **检查IDEA版本**:确保你的IDEA...

    从easyui里分离出来的grid控件

    5. 测试文件:用于单元测试和集成测试,确保控件的功能正常并符合预期。 总的来说,这个独立的Grid控件提供了一种高效、灵活的解决方案,特别适用于那些需要在旧版IE浏览器中运行的项目。通过深入理解其源代码和...

    code formatter编码风格

    自己用的一个code formatter编码风格

    SD Memory Card Formatter SD卡格式化工具

    SD Memory Card Formatter(SD 存储卡格式化程序)根据 SD 协会 (SDA) 创建的 SD 文件系统规范格式化 SD 存储卡、SDHC 存储卡和 SDXC 存储卡(分别为 SD/SDHC/SDXC 卡)。 强烈建议使用 SD Memory Card Formatter 来...

    eclispe中 java和js的Formatter

    5. **注释处理**:保留或删除注释,以及注释的缩进样式。 6. **块和循环的括号放置**:选择括号是否紧跟在关键字后,或者另起一行。 为了使团队成员共享和同步这些设置,Eclipse提供了导出和导入配置文件的功能。...

    SD Memory Card Formatter for Mac软件

    SD Memory Card Formatter for Mac 是专为Mac用户设计的SD存储卡格式化工具。它具有简单易用的界面,可快速而安全地格式化SD、SDHC、SDXC和MicroSD卡,以准备存储新数据。这款软件不仅能提高存储卡的性能,还有助于...

    Formatter_SiliconPower解除写保护神级软件.rar

    标题中的"Formatter_SiliconPower解除写保护神级软件.rar"指的是一个名为"Formatter_SiliconPower"的软件,主要用于解除存储设备的写保护状态。这个软件特别针对SiliconPower品牌的存储产品,可能是闪存驱动器、SD卡...

    WD_Quick_Formatter_Win_1_2_0_10

    西部数据的"WD_Quick_Formatter_Win_...总的来说,WD Quick Formatter是西部数据为用户提供的一款实用工具,旨在简化移动硬盘的维护工作,提高数据管理效率。了解并正确使用这款软件,可以有效地保护和管理您的WD硬盘。

Global site tag (gtag.js) - Google Analytics