wicketstuff / core

Wicketstuff-core projects are bundled user contributions for use with Apache Wicket (https://wicket.apache.org/). They are released in step with Wicket releases to make them easy to use.
336 stars 299 forks source link

Error when comparing model instead of object in NestedTree class #742

Closed leccyril closed 1 year ago

leccyril commented 1 year ago

In NestedTree abstract class (and Maybe in other components or classes) we use the model comparaison instead of object comparaison.

In IModel or in LoadableDetachableModel We don't have any equals method defined (no default nothing), it will use the default one what is false.

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() we must compare the object itself :

Objects.equals( model.getObject(), branch.getModelObject() )

martin-g commented 1 year ago

Why did you create two issues - this one and https://issues.apache.org/jira/browse/WICKET-7023 ?

leccyril commented 1 year ago

because i did not know where to create it because here it seems to be related another lib ? so have i to close this one ? amnd let other opened ?