You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Pedro Santos (JIRA)" <ji...@apache.org> on 2016/10/05 16:32:20 UTC
[jira] [Commented] (WICKET-3496) Component#setDefaultModelObject
should take in account IWrapModel
[ https://issues.apache.org/jira/browse/WICKET-3496?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15549238#comment-15549238 ]
Pedro Santos commented on WICKET-3496:
--------------------------------------
Is there a good reason to keep the instances equality test inside Component#setModelObject? I'm +1 to remove it.
A possible use case now that Wicket supports CDI: an user may want to change a component model object from a transient one to an equal one, but managed and with an associated persistence context after to start a long running conversation. In this case it would make sense to simply allow user to user Component#setModelObject and to trigger all the model changing and changed logic it needs.
> Component#setDefaultModelObject should take in account IWrapModel
> ------------------------------------------------------------------
>
> Key: WICKET-3496
> URL: https://issues.apache.org/jira/browse/WICKET-3496
> Project: Wicket
> Issue Type: Improvement
> Components: wicket
> Affects Versions: 1.4.16
> Environment: Win7, JDK 1.6u23, Jetty 6
> Reporter: Alexander Morozov
> Priority: Minor
> Attachments: myproject.7z
>
>
> Under some conditions, component's model object will not be updated (2), because
> of Component#defaultModelComparator (1). One of such kind of condition is default model that implements
> IWrapModel (see quickstart).
> Component#setDefaultModelObject:
> // Check whether this will result in an actual change
> if (!getModelComparator().compare(this, object)) //<<<<< 1 >>>>>>
> {
> modelChanging();
> model.setObject(object); //<<<<< 2 >>>>>>
> modelChanged();
> }
> I suggest that defaultModelComparator can be slightly improved to be able to extract and compare the real ("unwrapped") object,
> for example, by means of Component#getInnermostModel():
> Component#defaultModelComparator:
> private static final IModelComparator defaultModelComparator = new IModelComparator()
> {
> private static final long serialVersionUID = 1L;
> public boolean compare(Component component, Object b)
> {
> // final Object a = component.getDefaultModelObject(); //<<<<< 3 >>>>>>
> IModel<?> model = component.getInnermostModel(); // get "real" model
> final Object a = model.getObject();
> if (a == null && b == null)
> {
> return true;
> }
> if (a == null || b == null)
> {
> return false;
> }
> return a.equals(b);
> }
> };
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)