Skip to Content
0

SAP UI5 Hook

Jan 18 at 08:00 AM

49

avatar image
Former Member

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Arjun Biswas Jan 18 at 09:32 AM
0

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.

Show 3 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi Biswas ,

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

Regards

Jagjit Singh Saini

0

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

0
Former Member
Arjun Biswas

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

0