You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by Ryan Sonnek <ry...@gmail.com> on 2007/05/12 02:51:17 UTC

Re: [Wicket-user] inspecting model from IComponentInstantiationListener

I'm proposing adding a method to the IComponentInstantiationListener
(or a new interface) that would be invoked when a components model is
bound/attached/whatever.

I'd like to register a component listener that listens to every
component in my application and can configure it appropriately (by
inspecting the model and it's annotations).

Please let me know if this isn't really a good direction for wicket,
and if there should be a different way  to do this.  Thanks.

Ryan

On 5/11/07, Eelco Hillenius <ee...@gmail.com> wrote:
> On 5/11/07, Ryan Sonnek <ry...@gmail.com> wrote:
> > What exactly should a component instantiation listener be able to do?
> > I'm trying to build one that will inspect the model of every
> > component, but the model is not yet bound.  is there a way to register
> > a listener that is notified once the model is bound?
>
> There is none currenlty. Though I can imagine one. If you can argue a
> good use case, you could propose this on the dev list.
>
> Eelco
>
> -------------------------------------------------------------------------
> 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
>

Re: [Wicket-user] inspecting model from IComponentInstantiationListener

Posted by Johan Compagner <jc...@gmail.com>.
so when you make your component instantiation listener you have an enourmous
instance of if?
where you check for specific models? and then set something on that
component?

But the biggest problem is that what do you want to do exactly??
(in what ever case you have here)

for example if i do this:

MyComponent component = new MyComponent("test", new MyModel())

and you want to set a Validator because you see that MyModel is assigned
on that component. When do you want to do that??

when the model is assigned?? But that can't happen because this is where it
is assigned:
this is the current code:

public Component(final String id, final IModel model)
    {
        setId(id);
        getApplication().notifyComponentInstantiationListeners(this);
        this.model = wrap(model);

so you see the model is assigned later
But even if we did it earlier then you still can't do:

((FormComponent)component.setValidator(validatior)

that would be very wrong. Because the FormComponent instance isn't ready yet
(we are in the Component constructor)

Page.onAttach() method

and then with a visitor you walk over all the child components and test for
a specific
models you want. But then you have to remember where you did set the
validators on the previous time
(or do it only once if nothing does change but that can be hard with
changing models or dynamic components...)

This is by the way a nice catch i see now:
this line in the constructor:

this.model = wrap(model);

is pretty bad. because that does:

return ((IComponentAssignedModel)model).wrapOnAssignment(this);

that means we let the this escape in the constructor of a component. That is
bad programming.
But i dont see how we can solve this.. We just have to make sure in the docs
that this can happen...

johan

On 5/13/07, Ryan Sonnek <ry...@gmail.com> wrote:
>
> Even if the common logic was abstracted into an abstract class, you
> still have to update every model in the application to use this new
> abstract model.  This is a much more expensive change than registering
> an component instantiation listener.
>
> also, your assuming you can have *one* abstract model that satisfies
> *every* usecase.  Realistically, you'll have to recreate a large
> number customized models (Coumpound, Property, Nested, etc).  this is
> a real PITA.
>
> On 5/13/07, Johan Compagner <jc...@gmail.com> wrote:
> > But where are you testing it up with your
> ComponentInstantationListener??
> > If it really has to be for every model. Then you could have a common
> base
> > class
> > or just attach it auto on every (Form)component?
> >
> > johan
> >
> >
> > On 5/13/07, Ryan Sonnek <ry...@gmail.com> wrote:
> > >
> > > On 5/13/07, Johan Compagner <jc...@gmail.com> wrote:
> > > > but that can't be done on instantiation because you have no idea
> when
> > > the
> > > > model is set.
> > > > also you can have inhertiable models and so on.
> > > Understood.  That's why i need a "new" hook instead of
> onInstantiated()
> > >
> > > > But you want to do something when it has a specific model?
> > > > That can already be done
> > > > Let the model implement IComponentAssignedModel then you get a call:
> > > > wrapOnAssignment
> > > > just return this (that should work) and do you thing on the
> component
> > > you
> > > > get
> > > Okay, well that's a start.  The downfall with this approach is that
> > > you have to change *every* model in the system to use this interface.
> > > The reason for using the ComponentInstantiationListener is to make
> > > *sweeping* application wide changes in one spot.
> > >
> > > my current app is relatively small, so it's not that big of a deal.
> > > But the hibernate component instantiaion listener is useless without
> > > this new hook.
> > >
> >
>

Re: [Wicket-user] inspecting model from IComponentInstantiationListener

Posted by Ryan Sonnek <ry...@gmail.com>.
Even if the common logic was abstracted into an abstract class, you
still have to update every model in the application to use this new
abstract model.  This is a much more expensive change than registering
an component instantiation listener.

also, your assuming you can have *one* abstract model that satisfies
*every* usecase.  Realistically, you'll have to recreate a large
number customized models (Coumpound, Property, Nested, etc).  this is
a real PITA.

On 5/13/07, Johan Compagner <jc...@gmail.com> wrote:
> But where are you testing it up with your ComponentInstantationListener??
> If it really has to be for every model. Then you could have a common base
> class
> or just attach it auto on every (Form)component?
>
> johan
>
>
> On 5/13/07, Ryan Sonnek <ry...@gmail.com> wrote:
> >
> > On 5/13/07, Johan Compagner <jc...@gmail.com> wrote:
> > > but that can't be done on instantiation because you have no idea when
> > the
> > > model is set.
> > > also you can have inhertiable models and so on.
> > Understood.  That's why i need a "new" hook instead of onInstantiated()
> >
> > > But you want to do something when it has a specific model?
> > > That can already be done
> > > Let the model implement IComponentAssignedModel then you get a call:
> > > wrapOnAssignment
> > > just return this (that should work) and do you thing on the component
> > you
> > > get
> > Okay, well that's a start.  The downfall with this approach is that
> > you have to change *every* model in the system to use this interface.
> > The reason for using the ComponentInstantiationListener is to make
> > *sweeping* application wide changes in one spot.
> >
> > my current app is relatively small, so it's not that big of a deal.
> > But the hibernate component instantiaion listener is useless without
> > this new hook.
> >
>

Re: [Wicket-user] inspecting model from IComponentInstantiationListener

Posted by Johan Compagner <jc...@gmail.com>.
But where are you testing it up with your ComponentInstantationListener??
If it really has to be for every model. Then you could have a common base
class
or just attach it auto on every (Form)component?

johan


On 5/13/07, Ryan Sonnek <ry...@gmail.com> wrote:
>
> On 5/13/07, Johan Compagner <jc...@gmail.com> wrote:
> > but that can't be done on instantiation because you have no idea when
> the
> > model is set.
> > also you can have inhertiable models and so on.
> Understood.  That's why i need a "new" hook instead of onInstantiated()
>
> > But you want to do something when it has a specific model?
> > That can already be done
> > Let the model implement IComponentAssignedModel then you get a call:
> > wrapOnAssignment
> > just return this (that should work) and do you thing on the component
> you
> > get
> Okay, well that's a start.  The downfall with this approach is that
> you have to change *every* model in the system to use this interface.
> The reason for using the ComponentInstantiationListener is to make
> *sweeping* application wide changes in one spot.
>
> my current app is relatively small, so it's not that big of a deal.
> But the hibernate component instantiaion listener is useless without
> this new hook.
>

Re: [Wicket-user] inspecting model from IComponentInstantiationListener

Posted by Ryan Sonnek <ry...@gmail.com>.
On 5/13/07, Johan Compagner <jc...@gmail.com> wrote:
> but that can't be done on instantiation because you have no idea when the
> model is set.
> also you can have inhertiable models and so on.
Understood.  That's why i need a "new" hook instead of onInstantiated()

> But you want to do something when it has a specific model?
> That can already be done
> Let the model implement IComponentAssignedModel then you get a call:
> wrapOnAssignment
> just return this (that should work) and do you thing on the component you
> get
Okay, well that's a start.  The downfall with this approach is that
you have to change *every* model in the system to use this interface.
The reason for using the ComponentInstantiationListener is to make
*sweeping* application wide changes in one spot.

my current app is relatively small, so it's not that big of a deal.
But the hibernate component instantiaion listener is useless without
this new hook.

Re: [Wicket-user] inspecting model from IComponentInstantiationListener

Posted by Johan Compagner <jc...@gmail.com>.
but that can't be done on instantiation because you have no idea when the
model is set.
also you can have inhertiable models and so on.

But you want to do something when it has a specific model?
That can already be done
Let the model implement IComponentAssignedModel then you get a call:
wrapOnAssignment
just return this (that should work) and do you thing on the component you
get

johan


On 5/12/07, Ryan Sonnek <ry...@gmail.com> wrote:
>
>
> http://wicket-stuff.svn.sourceforge.net/viewvc/wicket-stuff/trunk/wicketstuff-hibernate-behavior/src/main/java/org/wicketstuff/hibernate/HibernateAnnotationComponentInstantiaionListener.java?revision=2135&view=markup
>
> If you look at the source, it should be a little easier to follow.
> I'm trying to register a listener that inspects the models of *all*
> components that will automatically register validators for that
> component.
>
> On 5/12/07, Johan Compagner <jc...@gmail.com> wrote:
> > what do you want to do there?
> > isn't that something for an IAuthorizationStrategy ?
> >
> > johan
> >
> >
> > On 5/12/07, Ryan Sonnek <ry...@gmail.com> wrote:
> > >
> > > I'm proposing adding a method to the IComponentInstantiationListener
> > > (or a new interface) that would be invoked when a components model is
> > > bound/attached/whatever.
> > >
> > > I'd like to register a component listener that listens to every
> > > component in my application and can configure it appropriately (by
> > > inspecting the model and it's annotations).
> > >
> > > Please let me know if this isn't really a good direction for wicket,
> > > and if there should be a different way  to do this.  Thanks.
> > >
> > > Ryan
> > >
> > > On 5/11/07, Eelco Hillenius <ee...@gmail.com> wrote:
> > > > On 5/11/07, Ryan Sonnek <ry...@gmail.com> wrote:
> > > > > What exactly should a component instantiation listener be able to
> do?
> > > > > I'm trying to build one that will inspect the model of every
> > > > > component, but the model is not yet bound.  is there a way to
> register
> > > > > a listener that is notified once the model is bound?
> > > >
> > > > There is none currenlty. Though I can imagine one. If you can argue
> a
> > > > good use case, you could propose this on the dev list.
> > > >
> > > > Eelco
> > > >
> > > >
> > >
> -------------------------------------------------------------------------
> > > > 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
> > > >
> > >
> >
>

Re: [Wicket-user] inspecting model from IComponentInstantiationListener

Posted by Ryan Sonnek <ry...@gmail.com>.
http://wicket-stuff.svn.sourceforge.net/viewvc/wicket-stuff/trunk/wicketstuff-hibernate-behavior/src/main/java/org/wicketstuff/hibernate/HibernateAnnotationComponentInstantiaionListener.java?revision=2135&view=markup

If you look at the source, it should be a little easier to follow.
I'm trying to register a listener that inspects the models of *all*
components that will automatically register validators for that
component.

On 5/12/07, Johan Compagner <jc...@gmail.com> wrote:
> what do you want to do there?
> isn't that something for an IAuthorizationStrategy ?
>
> johan
>
>
> On 5/12/07, Ryan Sonnek <ry...@gmail.com> wrote:
> >
> > I'm proposing adding a method to the IComponentInstantiationListener
> > (or a new interface) that would be invoked when a components model is
> > bound/attached/whatever.
> >
> > I'd like to register a component listener that listens to every
> > component in my application and can configure it appropriately (by
> > inspecting the model and it's annotations).
> >
> > Please let me know if this isn't really a good direction for wicket,
> > and if there should be a different way  to do this.  Thanks.
> >
> > Ryan
> >
> > On 5/11/07, Eelco Hillenius <ee...@gmail.com> wrote:
> > > On 5/11/07, Ryan Sonnek <ry...@gmail.com> wrote:
> > > > What exactly should a component instantiation listener be able to do?
> > > > I'm trying to build one that will inspect the model of every
> > > > component, but the model is not yet bound.  is there a way to register
> > > > a listener that is notified once the model is bound?
> > >
> > > There is none currenlty. Though I can imagine one. If you can argue a
> > > good use case, you could propose this on the dev list.
> > >
> > > Eelco
> > >
> > >
> > -------------------------------------------------------------------------
> > > 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
> > >
> >
>

Re: [Wicket-user] inspecting model from IComponentInstantiationListener

Posted by Johan Compagner <jc...@gmail.com>.
what do you want to do there?
isn't that something for an IAuthorizationStrategy ?

johan


On 5/12/07, Ryan Sonnek <ry...@gmail.com> wrote:
>
> I'm proposing adding a method to the IComponentInstantiationListener
> (or a new interface) that would be invoked when a components model is
> bound/attached/whatever.
>
> I'd like to register a component listener that listens to every
> component in my application and can configure it appropriately (by
> inspecting the model and it's annotations).
>
> Please let me know if this isn't really a good direction for wicket,
> and if there should be a different way  to do this.  Thanks.
>
> Ryan
>
> On 5/11/07, Eelco Hillenius <ee...@gmail.com> wrote:
> > On 5/11/07, Ryan Sonnek <ry...@gmail.com> wrote:
> > > What exactly should a component instantiation listener be able to do?
> > > I'm trying to build one that will inspect the model of every
> > > component, but the model is not yet bound.  is there a way to register
> > > a listener that is notified once the model is bound?
> >
> > There is none currenlty. Though I can imagine one. If you can argue a
> > good use case, you could propose this on the dev list.
> >
> > Eelco
> >
> >
> -------------------------------------------------------------------------
> > 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
> >
>