You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Igor Vaynberg <ig...@gmail.com> on 2010/07/13 04:09:14 UTC

new feature in trunk and branch: Component#onInitialize()

there have been a lot of threads over the years about having some
place to initialize components other than constructors. there are a
few problems with constructors, such as not being able to call
getPage() or non-final methods. historically we have refused to
implement this because we have maintained constructors were good
enough, but over the years i have seen a few usecases where something
like this would have been really nice. there have always been easy
workarounds that is why we were in no hurry to implement this, but i
think the time has come.

below is the javadoc from the method

	/**
	 * This method is meant to be used as an alternative to initialize
components. Usually the
	 * component's constructor is used for this task, but sometimes a
component cannot be
	 * initialized in isolation, it may need to access its parent
component or its markup in order
	 * to fully initialize. This method is invoked once per component's
lifecycle when a path exists
	 * from this component to the {@link Page} thus providing the
component with an atomic callback
	 * when the component's environment is built out.
	 * <p>
	 * Overrides must call super#{@link #onInitialize()}
	 * </p>
	 *
	 * <p>
	 * It is safe to use {@link #getPage()} in this method
	 * </p>
	 *
	 * <p>
	 * NOTE:The timing of this call is not precise, the contract is that
it is called sometime
	 * before {@link Component#onBeforeRender()}.
	 * </p>
	 *
	 */
	protected void onInitialize()
	{
	}

play around and see if you can find any problems. this will be part of
1.4.10 and 1.5.M1

-igor

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


Re: new feature in trunk and branch: Component#onInitialize()

Posted by James Carman <ja...@carmanconsulting.com>.
Very cool.  Thanks, Wicket Team!

On Mon, Jul 12, 2010 at 10:09 PM, Igor Vaynberg <ig...@gmail.com> wrote:
> there have been a lot of threads over the years about having some
> place to initialize components other than constructors. there are a
> few problems with constructors, such as not being able to call
> getPage() or non-final methods. historically we have refused to
> implement this because we have maintained constructors were good
> enough, but over the years i have seen a few usecases where something
> like this would have been really nice. there have always been easy
> workarounds that is why we were in no hurry to implement this, but i
> think the time has come.
>
> below is the javadoc from the method
>
>        /**
>         * This method is meant to be used as an alternative to initialize
> components. Usually the
>         * component's constructor is used for this task, but sometimes a
> component cannot be
>         * initialized in isolation, it may need to access its parent
> component or its markup in order
>         * to fully initialize. This method is invoked once per component's
> lifecycle when a path exists
>         * from this component to the {@link Page} thus providing the
> component with an atomic callback
>         * when the component's environment is built out.
>         * <p>
>         * Overrides must call super#{@link #onInitialize()}
>         * </p>
>         *
>         * <p>
>         * It is safe to use {@link #getPage()} in this method
>         * </p>
>         *
>         * <p>
>         * NOTE:The timing of this call is not precise, the contract is that
> it is called sometime
>         * before {@link Component#onBeforeRender()}.
>         * </p>
>         *
>         */
>        protected void onInitialize()
>        {
>        }
>
> play around and see if you can find any problems. this will be part of
> 1.4.10 and 1.5.M1
>
> -igor
>
> ---------------------------------------------------------------------
> 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


Re: new feature in trunk and branch: Component#onInitialize()

Posted by Erik van Oosten <e....@grons.nl>.
I always wonder about the order and worry what could go wrong. A small 
sentence in the javadoc would stop that. E.g. something simple like:

  * <p>
  * Markup containers are initialized prior to their children.
  * </p>

would be marvelous.

Regards,
      Erik.


Op 13-07-10 17:16, Igor Vaynberg wrote:
> On Tue, Jul 13, 2010 at 1:05 AM, vladimir.kovalyuk<ko...@gmail.com>  wrote:
>    
>> The sources shows that the markup container is initialized prior to children
>> initialization. As expected.
>>      
> im pretty sure that is a safe assumption to make, not sure if its
> javadoc worthy.
>
> -igor
>
>    
>> I used to double check due to onBeforeRender()
>> method. Should javadoc mention aforementioned?
>>
>> The great news is that onBeforeRender() will never be used for component
>> initialization just for rendering event.
>>
>> Looking forward for 1.4.10
>> --
>> View this message in context: http://apache-wicket.1842946.n4.nabble.com/new-feature-in-trunk-and-branch-Component-onInitialize-tp2286924p2287133.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> 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
>
>    

-- 
Sent from my SMTP compliant software
Erik van Oosten
http://day-to-day-stuff.blogspot.com/



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


Re: new feature in trunk and branch: Component#onInitialize()

Posted by Igor Vaynberg <ig...@gmail.com>.
i think in most cases it would make sense to call super first, just
like the constructor.

-igor

On Tue, Jul 13, 2010 at 8:35 AM, Josh Glassman <jo...@gmail.com> wrote:
> Nice, I have one or two places where onInitialize would make more sense than
> onBeforeRender. Thanks for the update!
>
> One question, does it matter where in the override we call super#onInitialize
> (beginning or end)?
>

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


Re: new feature in trunk and branch: Component#onInitialize()

Posted by Josh Glassman <jo...@gmail.com>.
Nice, I have one or two places where onInitialize would make more sense than
onBeforeRender. Thanks for the update!

One question, does it matter where in the override we call super#onInitialize
(beginning or end)?

Re: new feature in trunk and branch: Component#onInitialize()

Posted by Igor Vaynberg <ig...@gmail.com>.
On Tue, Jul 13, 2010 at 1:05 AM, vladimir.kovalyuk <ko...@gmail.com> wrote:
>
> The sources shows that the markup container is initialized prior to children
> initialization. As expected.

im pretty sure that is a safe assumption to make, not sure if its
javadoc worthy.

-igor

> I used to double check due to onBeforeRender()
> method. Should javadoc mention aforementioned?
>
> The great news is that onBeforeRender() will never be used for component
> initialization just for rendering event.
>
> Looking forward for 1.4.10
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/new-feature-in-trunk-and-branch-Component-onInitialize-tp2286924p2287133.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> 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


Re: new feature in trunk and branch: Component#onInitialize()

Posted by "vladimir.kovalyuk" <ko...@gmail.com>.
The sources shows that the markup container is initialized prior to children
initialization. As expected. I used to double check due to onBeforeRender()
method. Should javadoc mention aforementioned?

The great news is that onBeforeRender() will never be used for component
initialization just for rendering event.

Looking forward for 1.4.10
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/new-feature-in-trunk-and-branch-Component-onInitialize-tp2286924p2287133.html
Sent from the Wicket - User mailing list archive at Nabble.com.

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


Re: new feature in trunk and branch: Component#onInitialize()

Posted by Igor Vaynberg <ig...@gmail.com>.
onInitialize() is called only once, like the javadoc says.

-igor

On Mon, Jul 12, 2010 at 10:58 PM, Ernesto Reinaldo Barreiro
<re...@gmail.com> wrote:
> Igor,
>
> Thanks for this new feature!
>
> Just one question/remark... the JavaDoc of onBeforeRender states
>
> * Because this method is responsible for cascading {@link
> #onBeforeRender()} call to
> * children it is strongly recommended that super call is made at the
> end of the override.
>
> Is this also true for onInitialize? I understand from JavaDoc bellow
> that this method is called only once after component construction (on
> first request cycle?) so for more dynamic situations we still will
> need to use onBeforeRender. Is this assumption true?
>
> Cheers,
>
> Ernesto
>
> On Tue, Jul 13, 2010 at 4:09 AM, Igor Vaynberg <ig...@gmail.com> wrote:
>> there have been a lot of threads over the years about having some
>> place to initialize components other than constructors. there are a
>> few problems with constructors, such as not being able to call
>> getPage() or non-final methods. historically we have refused to
>> implement this because we have maintained constructors were good
>> enough, but over the years i have seen a few usecases where something
>> like this would have been really nice. there have always been easy
>> workarounds that is why we were in no hurry to implement this, but i
>> think the time has come.
>>
>> below is the javadoc from the method
>>
>>        /**
>>         * This method is meant to be used as an alternative to initialize
>> components. Usually the
>>         * component's constructor is used for this task, but sometimes a
>> component cannot be
>>         * initialized in isolation, it may need to access its parent
>> component or its markup in order
>>         * to fully initialize. This method is invoked once per component's
>> lifecycle when a path exists
>>         * from this component to the {@link Page} thus providing the
>> component with an atomic callback
>>         * when the component's environment is built out.
>>         * <p>
>>         * Overrides must call super#{@link #onInitialize()}
>>         * </p>
>>         *
>>         * <p>
>>         * It is safe to use {@link #getPage()} in this method
>>         * </p>
>>         *
>>         * <p>
>>         * NOTE:The timing of this call is not precise, the contract is that
>> it is called sometime
>>         * before {@link Component#onBeforeRender()}.
>>         * </p>
>>         *
>>         */
>>        protected void onInitialize()
>>        {
>>        }
>>
>> play around and see if you can find any problems. this will be part of
>> 1.4.10 and 1.5.M1
>>
>> -igor
>>
>> ---------------------------------------------------------------------
>> 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
>
>

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


Re: new feature in trunk and branch: Component#onInitialize()

Posted by Ernesto Reinaldo Barreiro <re...@gmail.com>.
Igor,

Thanks for this new feature!

Just one question/remark... the JavaDoc of onBeforeRender states

* Because this method is responsible for cascading {@link
#onBeforeRender()} call to
* children it is strongly recommended that super call is made at the
end of the override.

Is this also true for onInitialize? I understand from JavaDoc bellow
that this method is called only once after component construction (on
first request cycle?) so for more dynamic situations we still will
need to use onBeforeRender. Is this assumption true?

Cheers,

Ernesto

On Tue, Jul 13, 2010 at 4:09 AM, Igor Vaynberg <ig...@gmail.com> wrote:
> there have been a lot of threads over the years about having some
> place to initialize components other than constructors. there are a
> few problems with constructors, such as not being able to call
> getPage() or non-final methods. historically we have refused to
> implement this because we have maintained constructors were good
> enough, but over the years i have seen a few usecases where something
> like this would have been really nice. there have always been easy
> workarounds that is why we were in no hurry to implement this, but i
> think the time has come.
>
> below is the javadoc from the method
>
>        /**
>         * This method is meant to be used as an alternative to initialize
> components. Usually the
>         * component's constructor is used for this task, but sometimes a
> component cannot be
>         * initialized in isolation, it may need to access its parent
> component or its markup in order
>         * to fully initialize. This method is invoked once per component's
> lifecycle when a path exists
>         * from this component to the {@link Page} thus providing the
> component with an atomic callback
>         * when the component's environment is built out.
>         * <p>
>         * Overrides must call super#{@link #onInitialize()}
>         * </p>
>         *
>         * <p>
>         * It is safe to use {@link #getPage()} in this method
>         * </p>
>         *
>         * <p>
>         * NOTE:The timing of this call is not precise, the contract is that
> it is called sometime
>         * before {@link Component#onBeforeRender()}.
>         * </p>
>         *
>         */
>        protected void onInitialize()
>        {
>        }
>
> play around and see if you can find any problems. this will be part of
> 1.4.10 and 1.5.M1
>
> -igor
>
> ---------------------------------------------------------------------
> 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


Re: new feature in trunk and branch: Component#onInitialize()

Posted by Fernando Wermus <fe...@gmail.com>.
thanks you all

On Tue, Jul 13, 2010 at 12:19 AM, vineetsemwal
<vi...@gmail.com>wrote:

>
> very good feature,thanks!!
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/new-feature-in-trunk-and-branch-Component-onInitialize-tp2286924p2286961.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Fernando Wermus.

www.linkedin.com/in/fernandowermus

Re: new feature in trunk and branch: Component#onInitialize()

Posted by vineetsemwal <vi...@gmail.com>.
very good feature,thanks!!
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/new-feature-in-trunk-and-branch-Component-onInitialize-tp2286924p2286961.html
Sent from the Wicket - User mailing list archive at Nabble.com.

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