What may help is maybe having two interfaces IModelVersionable { Change getModelSnapshot() } and IModelObjectVersionable { Change getModelObjectSnapshot(); } to let the model control how it creates snapshots of objects and of itself.
then it can work like this
if modelobjectchanging is called:
IModel model=getModel();
if (model instanceof IModelObjectVersionable) {
// here a detachable model would have to return null because we have no way of knowing if the underlying object reference is transient
Change change=((IModelObjectVersionable)model).getModelObjectSnapshot();
} else {
Change change=new Change() { Object old=Objects.clone(model.getModelObject()); undo { model.setModelObject(clone); }
}
if (change!=null) {addStateChange(change);}
if modelchanging is called then we do the same but for the model itself not for its model object
however as you can see this would cause a paradigm shift of how detachable models work, it is no longer enough to simply declare the reference as transient, you need to implement IModelObjectVersionable and return null. so there are two things you need to do. maybe there is a more elegant solution that i do not see yet.
I also dont know about all these instanceof checks we would introduce. is that still a big performance concern?
-Igor
On 12/7/05, Christian Essl
<[EMAIL PROTECTED]> wrote:
I think this would be not such a big problem as long as addStateChange()
was public. A Model which needs versionioning of its internal state would
just take any component in the construtor and add the Change to it on
modification. In the end the changes will all endup in the page.
The Problem Igor and me were talking about is more about POJOs behind the
IModel which need to get versioned but do not know anything about
wicket-versioning. For such POJOs you have to version somehow from the
outside before you make a change. Currently you do this with
modelChanging() but I think this is broken.
Ie a FormComponent (or the IModel which does the change) must have a way
to indicate that it is now going to change the underlying POJO and that
the POJO should be saved for change.
To do this properly IMO component must have a way to decide
a) wheter the POJO should be versioned at all,
b) wheter a sourounding IModel (ie VersionablePOJOModel) takes care of the
versioning and the component just indicates that the pojo was changed
c) if not b) how to version it (clone() or something better).
Out of my head: Mybe we should make for such POJOs a cglib proxy which
does the versioning an setters - and keep the model versioionng (except
setModel()) out of Component. If a cglib proxy does not do it than the
user has to implenet a versionaware object.
Christian