关于 SAP UI5 MessageProcessor 消息创建的问题

简介: 关于 SAP UI5 MessageProcessor 消息创建的问题

我们在单步调试 SAP UI5 OData 模型或者 JSON 模型初始化代码时,都会发现 sap.ui.model.Model 构造函数调用了其基类 MessageProcessor 的构造函数,如下图所示:

3236ca8e24a2a436ca40ef13f61ead53_18cb529b494149ebc9bf898ef806a1ad.png

MessageProcessor 是 SAP UI5 统一存储和管理各种类型的 Message 的实现类之一。

以下是在 SAP UI5 里手动创建消息或扩展框架提供的消息传递功能的一些方法:


  • 可以通过中央 sap.ui.core.message.MessageManager API 手动创建自定义消息。 对于这些手动创建的消息,应用程序必须确保适当的消息生命周期。


  • 对于自定义目标格式,可以使用自定义消息处理器。 自己的消息处理器要继承类sap.ui.core.message.MessageProcessor。


  • 如果使用的后端以特殊方式提供消息,可以使用自己的sap.ui.core.message.MessageParser 实现。


Message Model


通过调用 getMessageModel() 方法从消息管理器中检索消息模型。可以直接在应用程序中使用它,也可以将它用作参考实现。


可以像使用任何其他模型一样使用消息模型将聚合绑定到根路径(/),例如列表中的项目,并添加过滤器和排序器。  /集合中的每个项目都代表一个 sap.ui.core.message.Message 对象,因此可以绑定到为此类对象指定的所有属性。 MessagePopover 控件用于向用户显示消息。


示例代码如下:

// "Button" required from "sap/m/Button"
// "MessagePopover" required from "sap/m/MessagePopover"
// "MessagePopoverItem" required from "sap/m/MessagePopoverItem"
var oMessagePopoverButton = new Button({
    text: "Show MessagePopover",
    type: "Accept",
    press: function() {
        oMP.openBy(this);
    }
});
var oMP = new MessagePopover({
    items: {
        path:"message>/",
        template: new MessagePopoverItem({ description: "{message>description}", type: "{message>type}", title: "{message>message}"})
    }
});
oMP.setModel(sap.ui.getCore().getMessageManager().getMessageModel(),"message");
oMessagePopoverButton.placeAt("content");


OData V2 Messages


OData V2 消息要么由 sap.ui.model.odata.ODataMessageParser 自动创建并由 sap.ui.model.odata.v2.ODataModel 处理,要么可以由应用程序手动创建。


这些消息的目标可以为空。 在这种情况下,消息没有特定目标并且与整个应用程序相关。如果设置了目标,则它必须对应于绑定路径,然后使用该路径将消息传播到相应的绑定。如果这些绑定属于实现 refreshDataState 函数的控件,则该控件能够对数据状态更改做出反应。


相关文章
|
5月前
|
前端开发 搜索推荐 开发者
SAP UI5 sap.m.Column 控件的 minScreenWidth 属性介绍
SAP UI5 sap.m.Column 控件的 minScreenWidth 属性介绍
|
5月前
|
JavaScript 前端开发 开发者
SAP UI5 控件 sap.m.ListBase 的 inset 属性的作用介绍
SAP UI5 控件 sap.m.ListBase 的 inset 属性的作用介绍
|
5月前
|
Web App开发 数据采集 前端开发
纯技术讨论:如何让 SAP UI5 应用无法被别人在浏览器里调试 - 这种做法不推荐试读版
纯技术讨论:如何让 SAP UI5 应用无法被别人在浏览器里调试 - 这种做法不推荐试读版
|
5月前
|
XML 存储 数据格式
SAP UI5 控件 customData 属性的应用介绍
SAP UI5 控件 customData 属性的应用介绍
|
5月前
|
前端开发 JavaScript API
SAP UI5 sap.ui.require.toUrl 的作用介绍
SAP UI5 sap.ui.require.toUrl 的作用介绍
|
5月前
|
搜索推荐
如何让 SAP UI5 Smart Table 支持多项选择(Multiple-Selection)试读版
如何让 SAP UI5 Smart Table 支持多项选择(Multiple-Selection)试读版
|
5月前
|
存储 安全 测试技术
使用 Visual Studio Code 创建 SAP UI5 项目遇到 self-signed security certificate 相关问题
使用 Visual Studio Code 创建 SAP UI5 项目遇到 self-signed security certificate 相关问题
|
5月前
|
开发者 UED
SAP UI5 SmartFilterBar 中 ControlConfiguration Aggregation 的作用介绍
SAP UI5 SmartFilterBar 中 ControlConfiguration Aggregation 的作用介绍
|
5月前
|
开发者 UED
关于 SAP UI5 sap.m.Column 的 demandPopin 属性
关于 SAP UI5 sap.m.Column 的 demandPopin 属性
SAP UI5 Link 控件的使用方法介绍 - 后续学习 Fiori Elements Smart Link 的基础试读版
SAP UI5 Link 控件的使用方法介绍 - 后续学习 Fiori Elements Smart Link 的基础试读版

热门文章

最新文章

下一篇
无影云桌面