Show TOC

Handling Events in XML ViewsLocate this document in the navigation structure

XML views use event handlers as attributes: The attribute name is the event name, such as "press" for a button, and the attribute value is the event handler name.

Depending on the syntax of its name, the event handler will be looked up by this name in different locations:

  • Names starting with a dot ('.') are always assumed to represent a method in the controller. They are resolved by removing the leading dot and reading the property with the resulting name from the controller instance. These names are 'relative' to the view/controller. Example:

    press: ".myLocalHandler" --> attachPress(oController["myLocalHandler"], oController);
    Note This syntax is by intention consistent to the complex binding syntax for formatter functions.
  • Names containing a dot at a later position are assumed to represent global functions and are resolved by calling jQuery.sap.getObject with the full name. Example:

    press: "some.global.handler" --> attachPress(jQuery.sap.getObject("some.global.handler"), oController);
  • Names without dot are interpreted as a relative name; if nothing is found, they are interpreted as an absolute name. This variant is only supported for backward compatibility. Example:

    press: "myHandler" --> if ( oController[myHandler"] ) {
      attachPress(oController["myHandler"], oController);
    } else {
      attachPress(jQuery.sap.getObject("myHandler"), oController);
    }

Irrespective of where the function was looked up, it will be executed with the controller as the context object (this). This is also true for global event handlers and makes the implementation of generic global handlers easier that may need an easy way back to the controller/view in which they are actually used, for example, to call createId or byId. This should make the development of global event handlers more consistent with controller local event handlers.

Therefore, the following declaration is equivalent to a call of controller.doSomething() when the button is pressed:

...
          <Button text="Press Me" press=".doSomething"/>
...