Search code examples
sapui5sap-fiorirap

SAP RAP-based Fiori Elements App does not trigger Events of Fragment


I built an oData V4-Service with the Restful Application Framework of SAP. I used this service to build a Fiori App (Fiori Elements). Now I try to create a custom action that will open a XML-Fragment (to upload a document and confirm/decline some data). But the Button-Actions of this Fragment will not be triggered.

I'm pretty new to Fiori Development, therefore I cannot explain why... I build my App by using tutorials I found on the internet.

This is my action I added to a Table on my Object Page of the Fiori App enter image description here

In my manifest.json I created this coding

"toOpenNotification/@com.sap.vocabularies.UI.v1.LineItem": {
  "actions": {
    "ExtEquipmentObjectPage": {
      "press": "my.custom.service.ext.controller.ExtEquipmentObjectPage.onClose",
      "visible": true,
      "enabled": true,
      "requiresSelection": true,
      "text": "Close Notification"
      }
    }
 }

This is calling the method onClose of ExtEquipmentObjectPage.

sap.ui.define([
    "sap/ui/core/mvc/Controller",
    "sap/ui/core/Fragment"
], function (Controller, Fragment) {
    'use strict';

    return {
        pDialog: null,



        onClose: function (oEvent) {
            //var oView = this.getView();
            if (!this.pDialog) {
                this.loadFragment({
                    // id: "excel_upload",
                    name: "my.custom.service.ext.fragment.ExcelUpload",
                    type: "XML",
                    controller: this
                }).then((oDialog) => {
                    //var oFileUploader = Fragment.byId("excel_upload", "uploadSet");
                    //oFileUploader.removeAllItems();
                    this.pDialog = oDialog;
                    this.pDialog.open();
                })
                    .catch(error => alert(error.message));
            } else {
                //var oFileUploader = Fragment.byId("excel_upload", "uploadSet");
                //oFileUploader.removeAllItems();
                this.pDialog.open();
            }
            debugger;
        },
        onUploadSet: function (oEvent) {
        },
        onTempDownload: function (oEvent) {
        },
        onCloseDialog: function (oEvent) {
            debugger;
            this.pDialog.close();
        },
        onBeforeUploadStart: function (oEvent) {
        },
        onUploadSetComplete: function (oEvent) {
        },
        onItemRemoved: function (oEvent) {
        }
    };
});

My fragment looks like this

<core:FragmentDefinition xmlns="sap.m" xmlns:l="sap.ui.layout" xmlns:core="sap.ui.core" xmlns:u="sap.ui.unified" xmlns:upload="sap.m.upload">
    <Dialog id="uploadDialogSet" title="Excel Upload">
        <content>
            <upload:UploadSet uploadEnabled="true" id="uploadSet" items="{path: '/', templateShareable: false}" fileTypes="pdf" maxFileNameLength="200" beforeUploadStarts="onBeforeUploadStart" uploadCompleted="onUploadSetComplete" afterItemRemoved="onItemRemoved"
            terminationEnabled="true">
                <upload:UploadSetItem id="uplSetIt" visibleRemove="true" visibleEdit="false" fileName="{name}" url="/upload">
                    <upload:attributes>
                        <ObjectAttribute id="ObjAttr" title="Uploaded by" text="{user}" active="false"/>
                    </upload:attributes>
                </upload:UploadSetItem>
            </upload:UploadSet>
        </content>
        <buttons>        
            <Button id="BtnTemplate" text="Success" press="onTempDownload" icon="sap-icon://accept" type="Success"/>
            <Button id="BtnUpload" text="Failure" press="onUploadSet" icon="sap-icon://error" type="Reject"/>
            <Button id="BtnClose" press="onCloseDialog" text="Cancel" icon="sap-icon://close-command-field"/>
        </buttons>
        <endButton>
            <Button id="BtnOk" press=".onCloseDialog" text="Ok"/>
        </endButton>    
    </Dialog>
</core:FragmentDefinition>

This opens the fragment in general enter image description here

But clicking on the Buttons for Success/Failure/Cancel does not trigger the methods like e.g. "onCloseDialog"...

My assumption is that I do not possess a "proper Controller", because methods like this.getView(), ... leading to an error. Therefore I tried something like

function (Controller, UIComponent, HashChanger, Log) {
        "use strict";

        return Controller.extend("my.custom.service.controller.ExtEquipmentObjectPage", {

but without success...

enter image description here

How can I achieve, that the actions will be triggered? Are there any examples somewhere?

I tried creating a different Controller with

return Controller.extend("my.custom.service.controller.ExtEquipmentObjectPage", {

but then I got some binding errors in my console...


Solution

  • Okay, I found a solution for myself.

    For my buttons I declared a Handler

    <Button core:require="{ handler: 'my/domain/appName/ext/controller/CustomActionHandler'}" id="BtnSuccess" press="handler.onSuccessClose" text="Success" icon="sap-icon://accept" type="Success"/>
    

    After this the methods of my handler were triggered