On Tue, 1 Feb 2011 08:52:03 -0800
Igor Vaynberg <igor.vaynb...@gmail.com> wrote:

> apparently some people also use it as a post-construct callback, which
> sort of makes sense. for example, to call overridable factory methods,
> which you cannot do from the constructor.
> 
> the solution is to delay all calls to oninitialize until just before
> the very first call to onconfigure.

You have just described both my usecase and the patch I submitted a
while ago ;-)

> i have mixed feelings about it
> because essentially when instantiating a new page you get an
> incomplete/lazy-initialized object and it is hard to have any useful
> methods on it that configure it further.

I understand the mixed feelings. However, I rarely find myself
instantiating a Page class manually and then doing anything other than
handing it to setResponsePage(). I think this could be sufficiently
guarded by putting a good explanation on onInitialize's javadoc.
Besides, by this logic, Component is also incompletely initialized
until the moment it gets added to the page.

In the meantime since the patch mentioned above was rejected, our
project went back to doing onBeforeRender with manual guard against
repeated post-construct initialization. This works. It has the
same drawback of being incomplete for a short duration, and it mixes
actual beforeRender stuff with late initialization, which can get
confusing. I think onInitialize would at least relocate these things to
a clearly visible and obvious spot. The bottom line is, you need to
know what you are doing if you do post-construct initialization, no
matter where you put that stuff. That said, it could be a more visible
spot than onBeforeRender ;-)

I'm +0.5 for going with my patch. 

Pro: - nice to have
     - makes Page consistent with Component

Con: - may break if an uninitialized Page (or Component!) is used
       carelessly. With Component this problem exists today already,
       at least until the component is added to its page. With Page it
       will not break existing code, since Page's onInitialize doesn't
       work properly at all at the moment.

     - not having it is not a showstopper


Carl-Eric
www.wicketbuch.de

Reply via email to