cancel
Showing results for 
Search instead for 
Did you mean: 

Add control listener?

Former Member
0 Kudos

Hi guys,

I want to call a certain function everytime a control gets created. I can think of 3 ways to do so:

  • Extend sap.ui.core.Control (super time-consuming in my opinion)
  • Extend a general sap.ui.core function (f.e. attachControlEvent) but I can't get this to work properly
  • Extend every layout I use (MatrixLayoutCells, HorizontalLayout etc) by extending their addContent method (seems dirty)



None of these options are suitable as of yet.

Did someone do some research on that topic and could share his results?

Or maybe other ideas/functionality SAPUI5 has to offer.

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

You can make use of onAfterRendering event handler of the control to call your own functions once the control is rendered in the UI,


oControl.addEventDelegate({

          onAfterRendering : function(oEvent){

                yourFunction();

       }

  });

-Sakthivel

former_member182372
Active Contributor
0 Kudos

that will be executed at every render, implementing one time action there might be overkill

Answers (2)

Answers (2)

Former Member
0 Kudos

Thank you guys for your answers.

I think I described my problem poorly so let me rephrase: I want to call a certain function everytime any control gets initialized.

So if my page contains a button, a text field and a dropdown box I need to extend every single control using your posted code lines. But to scan my code to find out which specific controls I'm using is super annoying and hard to maintain so I hoped there would be an easier way. But I guess there is no event which gets kind of called whenever any constructor gets used, right?

seVladimirs
Active Contributor
0 Kudos

And of course you can also try to play with overwriting existing super class methods, e.g. initialization of each Element. Please find example here - JS Bin - Collaborative JavaScript Debugging</title> <link rel="alternate" type=&q...

former_member182372
Active Contributor
0 Kudos

extend is not time consuming

JS Bin - Collaborative JavaScript Debugging</title> <link rel="alternate" type=&q...

just

sap.m.StandardListItem.extend('MyListItem', {

    init : function() {

      this.setProperty("info", "!!!");

    },

  renderer: function(oRm, oControl) {

  sap.m.StandardListItemRenderer.render.apply(this, arguments);

  }

});