2025 Feb 03 3:52 PM - edited 2025 Feb 03 4:00 PM
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:
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
Request clarification before answering.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
@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
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:
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:
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
User | Count |
---|---|
100 | |
11 | |
10 | |
9 | |
6 | |
5 | |
4 | |
4 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.