The child model's initModel() gets called first
There are no especial ordering programing to initModels calls. Basically
they are called by

    public final IModel<?> getDefaultModel()
    {
        IModel<?> model = getModelImpl();
        // If model is null
        if (model == null)
        {
            // give subclass a chance to lazy-init model
            model = initModel();
            setModelImpl(model);
        }

        return model;
    }
What about your custom component gain an model that implements
IComponentInheritedModel and assign his children default models with the
desired logic? On IComponentInheritedModel you can access your custom
component parent model, and if you use getDefaultModel method, you don't
need to care with initialization ordering too...

On Wed, Sep 30, 2009 at 9:51 AM, Edmund Urbani <e...@liland.org> wrote:

> Hi,
>
> I was just trying to create a component of my own which - in some of my
> pages -
> is created without a model. In the initModel() method I would then call
> super.initModel() and wrap the resulting model for use in a child
> component. The
> problem is the initialization order:
>
> The child model's initModel() gets called first, the parent (my custom
> component) does not yet have a model (getModelImpl() returns null) so it
> goes up
> farther in the component hierarchy and retrieves a wrong model.
>
> Looking at the Component source code (Wicket 1.4.1) I see a commented out
> line
> where initModel() used to to call the parent getModel() instead of
> getModelImpl(). There's also a comment explaining that doing so would
> "initialize many inbetween completely useless models". Well, not so useless
> for
> what I am trying to do I guess.
>
> So, from my perspective this looks like a bug that causes necessary
> initialization to be bypassed. Obviously though it was done like that on
> purpose, so I decided to put the issue up here instead of filing a bug
> report.
>
> Has anyone else run into similar issues?
> Would it really be so bad to just call getModel()?
>
> Cheers
>  Edmund
>
> --
> Liland ...does IT better
>
> Liland IT GmbH
> Software Architekt
> email: edmund.urb...@liland.at
>
> office: +43 (0)463 220111 | fax: +43 (0)463 220111 33 | mobil: +43 (0)699
> 122011 16
> http://www.Liland.at
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>


-- 
Pedro Henrique Oliveira dos Santos

Reply via email to