You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为Fiori Elements对象页设置Accept/Reject类型自定义操作按钮?

在Fiori Elements对象页添加带类型的自定义按钮

直接在manifest的自定义动作里加type属性不生效,是因为Fiori Elements对动作的UI配置有特定层级要求,你可以试试以下几种方法实现需求:

方法1:修正Manifest配置的层级结构

FE的自定义动作需要把按钮类型配置在settings.button节点下,而非直接放在action根节点。修改manifest.json配置如下:

1.1 定义自定义动作

在sap.ui5 -> routing -> targets -> 你的对象页target -> options -> settings -> actions中添加:

"actions": {
  "acceptEntity": {
    "text": "接受",
    "press": ".onAcceptEntity",
    "settings": {
      "button": {
        "type": "Accept"
      }
    }
  },
  "rejectEntity": {
    "text": "拒绝",
    "press": ".onRejectEntity",
    "settings": {
      "button": {
        "type": "Reject"
      }
    }
  }
}

1.2 将动作绑定到页脚

在同一个对象页的settings -> footer -> actions里引用这两个动作:

"footer": {
  "actions": {
    "acceptEntity": {},
    "rejectEntity": {}
  }
}

配置完成后,FE会自动渲染对应类型的按钮,无需额外代码。

方法2:通过控制器扩展手动添加按钮

如果manifest配置仍不生效,可以直接在对象页的扩展控制器里手动创建按钮并添加到页脚/页眉:

// 在对象页扩展控制器的onAfterRendering或onInit方法中
onAfterRendering: function() {
  // 获取对象页的页脚工具栏实例(固定ID为ObjectPageFooterToolbar)
  const oFooterToolbar = this.getView().byId("ObjectPageFooterToolbar");
  
  // 创建接受按钮
  const oAcceptBtn = new sap.m.Button({
    text: "接受",
    type: sap.m.ButtonType.Accept,
    press: this.onAcceptEntity.bind(this)
  });
  
  // 创建拒绝按钮
  const oRejectBtn = new sap.m.Button({
    text: "拒绝",
    type: sap.m.ButtonType.Reject,
    press: this.onRejectEntity.bind(this)
  });
  
  // 将按钮添加到页脚工具栏
  oFooterToolbar.addContent(oAcceptBtn);
  oFooterToolbar.addContent(oRejectBtn);
},

// 对应的事件处理函数
onAcceptEntity: function() {
  // 编写接受实体的业务逻辑
},

onRejectEntity: function() {
  // 编写拒绝实体的业务逻辑
}

方法3:使用XML片段加载自定义按钮

如果按钮UI需要更复杂的配置,可以用XML片段定义,再在控制器中加载:

3.1 创建XML片段(示例:CustomFooterButtons.fragment.xml)

<core:FragmentDefinition xmlns:core="sap.ui.core" xmlns:m="sap.m">
  <m:Button 
    text="接受" 
    type="Accept" 
    press=".onAcceptEntity" 
  />
  <m:Button 
    text="拒绝" 
    type="Reject" 
    press=".onRejectEntity" 
  />
</core:FragmentDefinition>

3.2 在控制器中加载片段

onInit: function() {
  const oFooterToolbar = this.getView().byId("ObjectPageFooterToolbar");
  // 加载片段并绑定当前控制器作为事件上下文
  const oButtonsFragment = sap.ui.xmlfragment("your.app.namespace.fragments.CustomFooterButtons", this);
  oFooterToolbar.addContent(oButtonsFragment);
}

以上三种方法都能实现带Accept/Reject类型的自定义按钮,优先推荐方法1,符合FE的配置规范;若配置不生效,再用方法2或3兜底。

内容的提问来源于stack exchange,提问作者Erch

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 00:00:04