John, Cemal - that method in AbstractPropertyModel absolutely does abide by
the contract - look at what it calls (getTarget()):

public final Object getTarget()
{
    Object object = target;
    while (object instanceof IModel)
    {
        Object tmp = ((IModel<?>)object).getObject();
        if (tmp == object)
            break;
        object = tmp;
    }
    return object;
}
John - I think you're right - it is unnecessary to implement IChainingModel
since there is no code in the wicket core codebase that calls it's methods.
Just make sure that if you nest models inside of other custom models, you do
call detach properly or you can end up with a memory leak.  You can see this
blog post as a simple example:
http://www.jeremythomerson.com/blog/2008/11/06/wicket-the-power-of-nested-models/

Hope this helps.

-- 
Jeremy Thomerson
http://www.wickettraining.com


On Thu, Dec 4, 2008 at 9:31 AM, jWeekend <[EMAIL PROTECTED]>wrote:

>
> John,
>
> Well spotted. AbstractPropertyModel implements IChainingModel but breaks
> its
> contract :
>  * Models that implement this interface will support chaining of IModels.
> getObject() of a
>  * IChainingModel should do something like:
>  *
>  * <pre>
>  * if ( object instanceof IModel) { return ((IModel)object).getObject()}
>  * else return object;
>  * </pre>
>
> Its getObject() implementation does not abide by this.
>        /**
>         * @see org.apache.wicket.model.IModel#getObject()
>         */
>        public Object getObject()
>        {
>                final String expression = propertyExpression();
>                if (Strings.isEmpty(expression))
>                {
>                        // Return a meaningful value for an empty property
> expression
>                        return getTarget();
>                }
>
>                final Object target = getTarget();
>                if (target != null)
>                {
>                        return PropertyResolver.getValue(expression,
> target);
>                }
>                return null;
>        }
>
> Regards - Cemal
> http://www.jWeekend.co.uk <http://www.jweekend.co.uk/>
> http://jWeekend.co.uk <http://jweekend.co.uk/>
>
>
>
> John Patterson wrote:
> >
> > Hi,
> >
> > I'm messing about with nested models and see the IChainingModel interface
> > which is implemented by the PropertyModels but its methods never actually
> > seems to be used.
> >
> > So I'm just checking that I haven't missed anything... for nested models
> I
> > don't actually need to implement this right?
> >
> > This is its def:
> >
> >
> > public interface IChainingModel<T> extends IModel<T>
> > {
> >       /**
> >        * Sets the model that is chained inside this model.
> >        *
> >        * @param model
> >        */
> >       public void setChainedModel(IModel< ? > model);
> >
> >       /**
> >        * Returns the chained model if there is a chained model.
> >        *
> >        * @return The chained model
> >        */
> >       public IModel< ? > getChainedModel();
> >
> > }
> >
> > Thanks,
> >
> > John
> >
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/IChainingModel-tp20835085p20835745.html
>  Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to