AbstractPropertyModel:
public AbstractPropertyModel(final Object modelObject)
{
if (modelObject == null)
{
throw new IllegalArgumentException("Parameter modelObject cannot
be null");
}
this.target = modelObject;
}
protected Object getTarget()
{
if (target instanceof IModel)
{
return ((IModel)target).getObject();
}
return target;
}
and get/setObject are just always returning or setting the same thing (the
property expression from the target)
now lets see CompoundPropertyModel
public CompoundPropertyModel(final Object model)
{
target = model;
}
public Object getObject()
{
if (target instanceof IModel)
{
return ((IModel)target).getObject();
}
return target;
}
public Object getTarget()
{
return target;
}
public void setObject(Object object)
{
this.target = object;
}
here we also have a getTarget() but in this class it does the opposite from
what it does in the property model..
it is just reverted just like getObject() is exactly a mirror on those 2
models.
I just don't like the compound variant this code just fails:
Model personModel= new Model(new Person());
CompoundPropertyModel model = new CompoundPropertyModel(personModel);
if (model.getObject() == personModel) {}
or
model.setObject(personModel);
Model personModel = (Model)model.getObject(); // FAILS!
Because generics will fail here:
public CompoundPropertyModel(final T model)
{
target = model;
}
public T getObject()
{
if (target instanceof IModel)
{
return ((IModel)target).getObject();
}
return target;
}
public void setObject(T object)
{
this.target = object;
}
So i looked at how we did that in 2.0:
public CompoundPropertyModel(Object target)
{
this.target = target;
}
@SuppressWarnings("unchecked")
public T getObject()
{
if (target instanceof IModel)
{
return (T)((IModel)target).getObject();
}
return (T)target;
}
public void setObject(T object)
{
this.target = object;
}
that just seems wrong.
johan