yes
i have now this, if anybody has some nice names:
package wicket;
/**
* Implementation of this interface can be used in the
Component.getComparator() for testing the
* current value of the components model data with the new value that is
given.
*
* @author jcompagner
*
*/
public interface IComparator
{
/**
* @param component The component for which the compare must take
place.
* @param newObject The object to compare the current value to.
* @return true if the current component model value is the same as
the newObject.
*/
boolean equals(Component component, Object newObject);
}
in component a private static final:
private static final IComparator comparator = new IComparator()
{
public boolean equals(Component component, Object newObject)
{
IModel model = component.getModel();
Object previous = model.getObject(component);
if(newObject == null && previous == null) return true;
if(newObject == null || previous == null) return false;
return newObject.equals(previous);
}
};
and the method that by default returns that default icomparator:
protected IComparator getComparator()
{
return comparator;
}
and it is finally used in:
public final Component setModelObject(final Object object)
{
final IModel model = getModel();
if (model != null)
{
if (!getComparator().equals(this, object))
{
modelChanging();
model.setObject(this, object);
modelChanged();
}
}
else
{
throw new IllegalStateException("Attempt to set model object
on null model");
}
return this;
}
now by default no one has to do anything, and the compare is much better.
If you have advanced compare. (Like later on with ajax if you really
have a distinction between
renderedValues and modelvalues then you can return another IComparator)
I don't like the names.. but can't find any better..
johan
Eelco Hillenius wrote:
Yeah, the != must go anyway. Actually, we shouldn't use == and !=
allmost anywhere, as this is bound to give problems in a (distributed)
web environment anyway.
Take care not to forget any null checks though.
Eelco
On 8/29/05, Johan Compagner <[EMAIL PROTECTED]> wrote:
this is currently the method of component for setting the model object
value:
public final Component setModelObject(final Object object)
{
final IModel model = getModel();
if (model != null)
{
if (model.getObject(this) != object)
{
modelChanging();
model.setObject(this, object);
modelChanged();
}
}
else
{
throw new IllegalStateException("Attempt to set model object
on null model");
}
return this;
}
That compare if (model.getObject(this) != object) is a bit wrong.
Because if it comes from the web. Then the object is always different...
because of ==
We should do there some better equals code.
But if it is a shared model. Then it is possible that another already
changed the value of that model
and you are just pushing a old value. This can't be catched currently
very easy (only in model.setObject with some tricks)
so i want to make something like this:
if (getComparator().isChanged(model, object))
{
modelChanging();
model.setObject(this, object);
modelChanged();
}
and the default one does a better test then it does currently...
any body has a nicer/better idea?
johan
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Wicket-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-develop
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Wicket-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-develop
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Wicket-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-develop