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

🏷️

This is about the life cycle of SAPUI5 controllers.

Understand the life cycle and its hooks.

Knowing the SAPUI5 controller life cycle is one of the SAPUI5 fundamentals.

Let’s get right into it!

The Life Cycle of an SAPUI5 controller

SAPUI5 controllers provide lifecycle hooks.

Those hooks are based on the life cycle of the controller’s view.

A view starts the process of instantiating the controller:

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

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

The onBeforeRendering and onAfterRendering methods are called every time a view is invoked.

For example, invoke a method every when the view is instantiated in the controller’s onInit method:

// in your controller
 
...

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

Or, you can invoke a method every time after the view is rendered in the controller’s onAfterRendering method:

// 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 life cycle of a control in SAPUI5.

🔥 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. 

📚 More Articles

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

🚀 Upgrade Your Work Experience With Altwork (Welcome to the Future)

altwork_picture_2

The Altwork Station redefines how people interact with their computers by allowing the computer screen and keyboard to physically conform to support the user’s body while working long hours on a computer.

Submission received, thank you!

Close Window