[
https://issues.apache.org/jira/browse/WICKET-7023?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Sven Meier closed WICKET-7023.
------------------------------
Assignee: Sven Meier
Resolution: Not A Problem
Please read the javadoc of ITreeProvider#model(T):
"Important note: The model must implement \{@link Object#equals(Object)} and
\{@link Object#hashCode()} !"
This implementation was chosen deliberately to prevent unnecessary calls to
#getObject().
Please use a custom implementation, if not default does it for you. Many
projects have something like JpaEntityModel. See
org.apache.wicket.examples.tree.FooProvider/FooMode for inspiration.
And please use the mailing list for questions the next time.
> Problem when comparing model instead of object in NestedTree class
> -------------------------------------------------------------------
>
> Key: WICKET-7023
> URL: https://issues.apache.org/jira/browse/WICKET-7023
> Project: Wicket
> Issue Type: Bug
> Components: wicket-extensions
> Affects Versions: 9.12.0
> Environment: Linux
> Reporter: leclerc cyril
> Assignee: Sven Meier
> Priority: Major
>
> 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
> {code:java}
> @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();
> }{code}
> {{}}
> 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)
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)