Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Not A Problem
-
9.12.0
-
None
-
None
-
Linux
Description
In NestedTree abstract class (and Maybe in other components or classes) we use the model comparaison instead of object comparaison (model.getObject()).
In IModel or in LoadableDetachableModel We don't have any equals method defined (no default, nothing), it will use the default one what is not good.
example (l111) of NestedTree.java in wicket-extensions library
@Override public void updateBranch(T t, IPartialPageRequestHandler target) { final IModel<T> model = getProvider().model(t); visitChildren(BranchItem.class, new IVisitor<BranchItem<T>, Void>() { @Override public void component(BranchItem<T> branch, IVisit<Void> visit) { if (model.equals(branch.getModel())) { // BranchItem always outputs its markupId target.add(branch); visit.stop(); } } }); model.detach(); }
{{}}
Instead of comparing model.equals(branch.getModel() should we use instead the object comparaison itself :
Objects.equals( model.getObject(), branch.getModelObject() )
because here model are different and not same ref , it will always return false ? or i miss something ?
If not could you explain us why we have to use the model and what to do to make it work properly ?
Even we use a custom extension of LoadableDetachableModel if we override the model equals we have to check the state, if state is attached, get the transient object and compare it, if not attached, compare the unid. Moreover it is possible in wicket core or other librairies to compare 2 models not attached (so finally quite ugly equals no ?).
What is the default behaviour of comparing models if we used the default models in wicket ? because even in wicket models (CompoundPropertyModel for instance no equals is defined)