Skip to Content
avatar image
Former Member

SAP UI5 Hook

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Jan 18 at 09:32 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

    • 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