cancel
Showing results for 
Search instead for 
Did you mean: 

SAP UI5 Hook

jagjit_saini2
Explorer
0 Kudos

Hi ,

Can anyone explain me the what is difference between CreatContent and Onit in SAP UI5 . Both these methods are getting called before display of view . So what is the difference between these two .

Regards

Jagjit Singh Saini

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member484715
Contributor
0 Kudos

Hi Jagjit Saini,

Its a very good question. There are lots of differences, in between the two methods,

createContent() :

  • It is used in the JS view.
  • It is called initially once after the controller has been instantiated.
  • This method is used to create the UI controls.
  • It is not one of the lifecycle hook methods.

onInit() :

  • It is used in the controller.
  • It is called when a view is instantiated and its controls (if available) have already been created.
  • It is used to modify the view before it is displayed to bind event handlers and do other one-time initialization.
  • It is an controller lifecycle hook method.

The main difference is that usually the createContent method is used in the view to create the UI controls, that will be rendered on the browser. But the onInit method doesnot contain any UI controls and, is used only for one time initialization such as binding and routing. If you want any control to be displayed, the create content method is mandatory for the JS views. But if you are not initializing or performing an one time global operation, you can omit the onInit method also.

Hope this helps,

Regards,

Arjun Biswas.

jagjit_saini2
Explorer
0 Kudos

Hi Biswas ,

But i could see that Create Content is called before Onit . Why it is like this ?

Regards

Jagjit Singh Saini

former_member484715
Contributor
0 Kudos

Hi Saini,

Create content is called whenever the view is instantiated, so that the controls can be rendered. Once the create content is called, then only the onInit of the controller will be called.

Regards,

Arjun Biswas

jagjit_saini2
Explorer
0 Kudos

Hi Biswas ,

Thanks I got it . But one more doubt on OnBeforeRendering. As far as i understand , this method will trigger before rendering of view control on html page. So I should not be able to get control using ById method in OnBeforeRendering . But to my surprise , I am able to access it . Could you please explain me why this is happing .

Regards

Jagjit Singh Saini