When will com.itmill.toolkit.ui.AbstractComponent.getApplication return nul

Hi,

Sometimes I need to get a handle to the Application object inside a CustomComponent but getApplication() returns null. Why is this? When will getApplication() return null and is there a way to get to the Application object when it does?

Thank you for your attention,

Johnny

Hmm…

Are you sure that when you do the .getApplication() , your component has been added to your application ?

getApplication() can only be called after the component is attached to the app.

Quentin.

Quentin,

Actually, at the time getApplication() is called, my CustomComponent is in the process of being added to a window - getApplication() is called in the CustomComponent’s constructor. From what you write I can’t call getApplication() there. So, how can I get hold of the application object in the constructor of a CustomComponent?

Best regards,

Johnny

Well… Calling getApplication() in the constructor is something that just do not work - well, at least it never worked for me :stuck_out_tongue:
By definition, in the constructor of the CustomComponent, the component is not yet added to the application - and thus cannot access it.
If you really, really need that, maybe sending the application as constructor parameter ?

What I do when I need to init a component using the application is either to use a separate init method that I call after I added the component ; or on some tricky case, override the attach() method on the CustomComponent (calling super.attach() on the first line, and then doing all the specific init).

Quentin.

Thanks, either should do the trick.

Best regards,

Johnny