You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Martin Dietze <di...@fh-wedel.de> on 2013/02/20 15:12:09 UTC

Style question: onInitialize() vs. onBeforeRender()

While porting my project from 1.4.x to 6.6.0, I've stumbled
across the onInitialize() method which is now recommended for
initializing components which need access to the page instance
etc. In my project this had so far been done in onBeforeRender()
(and this seems to still work fairly well). 

Is moving that code to onInitialize() in such cases generally
advisable, if yes, should this be done immediately? 

Cheers,

M'bert

-- 
----------- / http://herbert.the-little-red-haired-girl.org / -------------
=+= 
"That's right," yelled Vroomfondel, "we demand rigidly defined areas of 
doubt and uncertainty!"  -- Douglas Adams

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Style question: onInitialize() vs. onBeforeRender()

Posted by Thomas Götz <to...@decoded.de>.
Note the difference between onInitialize() and onBeforeRender() as stated in the JavaDoc:

onInitialize()  : "...This method is invoked once per component's lifecycle …"
onBeforeRender(): "Called just before a component is rendered."

Meaning: onBeforeRender() is called upon *each* request whereas onInitialize() is called only *once* for each component. So, my recommandation: put all (static) initalization code into onInitialize().
If you need to do something per request, also have a look at onConfigure(), which is guaranteed to be called only *once* per request (in contrast to onBeforeRender, which might get called multiple times per request AFAIK).

   -Tom


On 20.02.2013, at 15:12, Martin Dietze <di...@fh-wedel.de> wrote:

> While porting my project from 1.4.x to 6.6.0, I've stumbled
> across the onInitialize() method which is now recommended for
> initializing components which need access to the page instance
> etc. In my project this had so far been done in onBeforeRender()
> (and this seems to still work fairly well). 
> 
> Is moving that code to onInitialize() in such cases generally
> advisable, if yes, should this be done immediately? 
> 
> Cheers,
> 
> M'bert
> 
> -- 
> ----------- / http://herbert.the-little-red-haired-girl.org / -------------
> =+= 
> "That's right," yelled Vroomfondel, "we demand rigidly defined areas of 
> doubt and uncertainty!"  -- Douglas Adams
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org