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 <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]> wrote:
> >
> > On 5/13/07, Johan Compagner <[EMAIL PROTECTED]> 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.
> >
>

Reply via email to