i do not think we will allow what you want here.
this listener is invoked during the construction of the component, it is
really UNSAFE to call any methods on that component because it is still
being constructed. the only safe method to call is getid(), thats it. that
much is expressed in the javadoc.
that argument should have been Class<? extends Component> instead of
Component, but for various reasons that have to do with resource injection
we have conceeded and made it Component - that doesnt mean you can go and
start calling whatever methods you want on it.
besides, what if i do new Component().setModel(foo) instead of new
Component(id, foo); then your instantiation listener is out of luck anyways.
the only good way is to add a behavior like was suggested and intercept at
proper points. of course without knowing your exact usecase its hard to
help.
-igor
On 6/18/07, Alberto Bueno <[EMAIL PROTECTED]> wrote:
I know IComponentOnBeforeRenderListener, but I cannot use this
interface, because I need to condition
the instantiation of the children of my component, depending of the
functionality of the Listener.
And if I use IComponentOnBeforeRenderListener, the instantiation has
been finished when the interface
is called.
The best moment to use this functionality is in the
IComponentInstantiationListener... because any children
have been still instantiated.
> There is now - since a few weeks - also
> org.apache.wicket.application.IComponentOnBeforeRenderListener, which
> may suit your needs better.
>
> We (Teachscape) use it like:
>
> public final class ValidationListener implements
> IComponentOnBeforeRenderListener {
>
> public void onBeforeRender(Component component) {
> if (component instanceof FormComponent &&
!component.hasBeenRendered()) {
> // add validators
> processComponent((FormComponent) component);
> }
> }
>
> and in our application's init method:
>
> addComponentOnBeforeRenderListener(new ValidationListener());
>
>
> Eelco
>
> On 6/18/07, Alberto Bueno <[EMAIL PROTECTED]> wrote:
>
>> Hi,
>>
>> I'm using IComponentInstantiationListener to add additional
>> functionality to my components. But in this listener I need to know the
>> model of the component to condition this functionality.
>> If we inspect the code, we can see that the listeners are called before
>> assigning the model to the component:
>>
>> public Component(final String id, final IModel model)
>> {
>> setId(id);
>> getApplication().notifyComponentInstantiationListeners(this);
>> this.model = wrap(model);
>>
>> final IDebugSettings debugSettings =
>> Application.get().getDebugSettings();
>> if (debugSettings.getComponentUseCheck())
>> {
>> setMetaData(CONSTRUCTED_AT_KEY, Strings.toString(this, new
>> MarkupException(
>> "constructed")));
>> }
>> }
>>
>> Are there any reason to do the notification in that moment?
>>
>> Thanks
>>
>>
>>
>>
-------------------------------------------------------------------------
>> This SF.net email is sponsored by DB2 Express
>> Download DB2 Express C - the FREE version of DB2 express and take
>> control of your XML. No limits. Just data. Click to get it now.
>> http://sourceforge.net/powerbar/db2/
>> _______________________________________________
>> Wicket-user mailing list
>> Wicket-user@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/wicket-user
>>
>>
>
>
-------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Wicket-user mailing list
> Wicket-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/wicket-user
>
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user