Adding child components in constructor? Best practice?

2008-07-31 Thread pixologe

Hi everybody,
May sound stupid: is the contructor really the best place for adding
children to a component or is there a better one, e.g. onBeforeRender?

All examples I see keep doing this in the constructor or in an init method
which is called by the constructor, however, I realized that there are some
problems e.g. if the component needs a string resource from the page or
anything else from a parent element (because it is not attached to the page
while still not being fully constructed).

Are there any drawbacks when doing this in onBeforeRender?

Btw: If you say a component should not need to access to its parent, you
are probably right for most cases, but there are scenarious where it does.

Thanks for inspiration :)
-- 
View this message in context: 
http://www.nabble.com/Adding-child-components-in-constructor--Best-practice--tp18760471p18760471.html
Sent from the Wicket - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Adding child components in constructor? Best practice?

2008-07-31 Thread Igor Vaynberg
you can feel free to do it in onbeforerender. this pattern is used,
for example, when you need to have user-overridable factory methods
for child components. the constructor works for 90% usecase and does
not require extra checks like onbeforerender because you know the
constructor only runs once.

as for needing access to string resources, you are right unless of
course you use a model such as ResourceModel which delays the lookup
until it is actually needed.

-igor

On Thu, Jul 31, 2008 at 11:15 AM, pixologe [EMAIL PROTECTED] wrote:

 Hi everybody,
 May sound stupid: is the contructor really the best place for adding
 children to a component or is there a better one, e.g. onBeforeRender?

 All examples I see keep doing this in the constructor or in an init method
 which is called by the constructor, however, I realized that there are some
 problems e.g. if the component needs a string resource from the page or
 anything else from a parent element (because it is not attached to the page
 while still not being fully constructed).

 Are there any drawbacks when doing this in onBeforeRender?

 Btw: If you say a component should not need to access to its parent, you
 are probably right for most cases, but there are scenarious where it does.

 Thanks for inspiration :)
 --
 View this message in context: 
 http://www.nabble.com/Adding-child-components-in-constructor--Best-practice--tp18760471p18760471.html
 Sent from the Wicket - User mailing list archive at Nabble.com.


 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]