SAPUI5: What Is the Life Cycle of a Controller? (+Example)

🏷️

This is about the life cycle of an SAPUI5 controller.

Understand the life cycle and its hooks.

Let’s get right into it!

The Life Cycle of an SAPUI5 controller

An SAPUI5 controller provides life cycle hooks. Those hooks base on the life cycle of the controller’s view.

A view kicks-off the instantiation of a controller:

  • Application invokes a view
  • Instantiate the view and its controller
  • Load controller
  • onInit hook (after the view is instantiated)
  • onBeforeRendering hook (before view is rendered)
  • onAfterRendering hook (after view is rendered)
  • onExit hook (after view is destroyed)
  • Controller is destroyed

The onInit and onExit methods are called exactly one time per view instantiation.

The onBefore rendering and onAfter rendering methods are called every time a view gets invoked.

For example, call a method in the controller’s onAfter rendering method to invoke a method every time after the controller’s view is rendered:

// in your controller
 
...

// hook gets invoked after the view is rendered  
onAfterRendering: function() {
 
  this.fooBar();
 
},
 
fooBar: function() {
 
  sap.base.Log.info("foo bar");
    
}
  
...

Here is the order in which an application executes in SAPUI5.

And here is the lifecycle of a control in SAPUI5.

🙌 More Articles

🔥 The Complete SAP ERP Modules Overview Infographic in PDF Format (Free)

Plus, don't miss future infographics and free SAP tips and insights that are available only to newsletter subscribers. 

Leave a Comment

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

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu