cancel
Showing results for 
Search instead for 
Did you mean: 

List Report Controller Extension - custom button plus lifecycle method overrides

RaminS
Active Participant
0 Kudos
360

I needed to add an action button to a custom List Report app. I used the usual action button controller extension to add the button and process the press event:

manifest:

 

 "extends": {
            "extensions": {
                "sap.ui.controllerExtensions": {
                    "sap.suite.ui.generic.template.ListReport.view.ListReport": {
                        "controllerName": "... .equipbcodelr.ext.controller.ListReportExt",
  "sap.ui.generic.app": {
    "zqmm_c_equipment_bc": {
      "EntitySet": "zqmm_c_equipment_bc",
        "Actions": {
          "barcodeSearch": {
            "id": "barcodeSearch",
            "text": "Barcode Search",
            "press": "scanMe",
            "requiresSelection": false
          },

 

 ext controller:

 

sap.ui.define([
  "sap/m/MessageToast"
], function(MessageToast) {
  "use strict";

  return { 
      scanMe: function(oEvent) {
          MessageToast.show("Custom handler invoked.");
          ...

 

This works great. However, I also want to override the onInit( ) method of the controller to prep a local JSON model. It does not allow me to override the lifecycle methods. To override the lifecycle methods I found out my controller needs to be like this:

 

sap.ui.define([
  "sap/ui/core/mvc/ControllerExtension",
	"sap/suite/ui/generic/template/extensionAPI/extensionAPI"
], function(ControllerExtension, BaseObject,ExtensionAPI) {
    'use strict';

  return ControllerExtension.extend("...ext.controller.ListReportExt",{
      override:{
        onInit: function(oEvent){
              . . .

 

As soon as I change my controller to:

RaminS_0-1738598439468.png

it no longer executes the press event of my custom action function scanMe: function( ).

How can I combine these two, have my controller handle the custom action button as well as override the lifecycle methods like onInit( )?

Would appreciate any hints.

Thanks

View Entire Topic
Marian_Zeis
Active Contributor
0 Kudos

I think you two js files and use for your action like:

          "barcodeSearch": {
            "id": "barcodeSearch",
            "text": "Barcode Search",
            "press": "... .equipbcodelr.ext.controller.ListReportActionExt.scanMe",
            "requiresSelection": false
          },

So one file for your controller extension and one for the press action.

Also i recommend to do everything (creating custom action, creating controller extension) with the Fiori tools, so you dont have to worry about the details here. 

RaminS
Active Participant
0 Kudos

Hi @Marian_Zeis 

I did use Fiori Tools (Guided dev) to create my custom action. It updated my manifest and created the controller like this:

 

sap.ui.define([
  "sap/m/MessageToast"
], function(MessageToast) {
  "use strict";

  return { 
      scanMe: function(oEvent) {
          MessageToast.show("Custom handler invoked.");
          ...

 

But that doesn't allow overriding hook methods. And there are no guided tools to extend base controller. 

 

Marian_Zeis
Active Contributor
0 Kudos

@RaminSyes, you´re right, but with the Page Map you can creater controller extension, hier you can create a different file for the controller extension, now you have two files, one for the controller extension and one for the custom action

Marian_Zeis_0-1738848736095.png

 

RaminS
Active Participant
0 Kudos

Hi @Marian_Zeis 

My page map only shows the following:

RaminS_0-1738850772561.png

 

Marian_Zeis
Active Contributor
0 Kudos
you can have a look at this manifest, here is use also two files for controller extension and custom action https://github.com/spreadsheetimporter/ui5-cc-spreadsheetimporter/blob/main/examples/packages/orders...
RaminS
Active Participant
0 Kudos

Hi @Marian_Zeis 

I created two .js files as you suggested, one to override hook methods of the base controller, and one for my actions. My actions were defined by the Guided Dev tool under the extended controller in the manifest, so I changed it to:

RaminS_0-1738859891342.png

But this does not work, my actions are not being called.

I noticed in your manifest, you define your actions under content of your "targets". Do I have to do that? 

Fiori Tools does not give me an option to add Actions:

RaminS_1-1738860045521.png

 

 

RaminS
Active Participant
0 Kudos

Hi @Marian_Zeis 

Do you know why your Fiori tools show the button "Add Controller Extension" but mine doesn't?

Is it a cloud-only option, do we have to be in oData v4 or is there another minimum requirement?

Thanks