SAPUI5 Addressing the Event Handler

Ever wonder why a function on your XML view doesn’t work? In this post we will focus on understanding how XML view event handler really works.

Addressing the Event Handler

dot(.) is not the end

Unlike common sentences where a dot(.) represents an end of a statement. Dot(.) that precedes a function declaration in an XML view actually represent a start. It represents a start to a local controller function call.

Local Functions
Local Functions

This syntax is by intention consistent to the complex binding syntax for formatter functions.

-SAP

core:require are static

If the function statement doesn’t start with dot(.), SAPUI5 will try to resolve on static core: require.

In code above, Box.show will be looked up from the dependencies imported at the declarative level.

Upon checking SAPUI5 SDK, i noticed that the core: require is documented to start at version 1.69.0.

Succeeding dots(.) are static or global

If the dots(.) are not at the start, they are either resolve to relative or XML dependencies, if not found, SAPUI5 will look it up on the global scope.
SAPUI5 though warns that we should limit global functions as best practice, to prevent unwanted changes out of scope.

In code above, my.global.module.alert will be looked up from the global scope since it cannot found in the XML or controller level.

No dots(.), no problem it must be relative or global?!

If all rules above fails, the default behavior is to look it up on a higher scope. First relative, then on a global scope.

Summary

In summary you can easily look up on the table below for reference on how these an event handler work.

Dot OperatorControllerXML ModuleGlobal
Starts with dot(.)YesNoNo
Succeeding dots(.)NoYesYes
No dots(.)NoYesYes

Any question or suggestion? let me know in the comment section below. Don’t forget to share and subscribe!

For more tutorials check out my post on SAPUI5 for beginners or checkout my GitHub repository for SAPUI5 Best Practices.


Leave a Reply

One thought on “SAPUI5 Addressing the Event Handler

  1. sirglio frei Reply

    Awsome blog! I am loving it!! Will be back later to read some more. I am bookmarking your feeds also.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.