| Author |
Message |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 24/07/2008 13:21:21
|
Johnny
Joined: 16/07/2008 17:44:11
Messages: 15
Offline
|
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
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 24/07/2008 15:49:29
|
QuentinAstegiano
Joined: 16/01/2008 15:10:43
Messages: 38
Location: Paris, France
Offline
|
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.
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 24/07/2008 16:03:58
|
Johnny
Joined: 16/07/2008 17:44:11
Messages: 15
Offline
|
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
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 24/07/2008 16:12:28
|
QuentinAstegiano
Joined: 16/01/2008 15:10:43
Messages: 38
Location: Paris, France
Offline
|
Well... Calling getApplication() in the constructor is something that just do not work - well, at least it never worked for me :p
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.
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 24/07/2008 16:19:27
|
Johnny
Joined: 16/07/2008 17:44:11
Messages: 15
Offline
|
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).
Thanks, either should do the trick.
Best regards,
Johnny
|
|
|
 |
|
|