[ 
https://issues.apache.org/jira/browse/WICKET-3496?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13002918#comment-13002918
 ] 

Alexander Morozov commented on WICKET-3496:
-------------------------------------------

Thank you Martin. That's the point. What if we change defaultModelComparator 
impl as below:

        ... = new IModelComparator()   {

          public boolean compare(Component component, Object newObject) {
             // init and get component's model
            IModel<?> model = component.getDefaultModel();
            if (model instanceof IWrapModel) {
              // if the real model wrapped - unwrap
              model = ((IWrapModel<?>) model).getWrappedModel();
            }
            Object thisObject = (model == null ? null : model.getObject());
            if (thisObject == null && newObject == null) {
              return true;
            }
            if (thisObject == null || newObject == null) {
              return false;
            }
            return thisObject.equals(newObject);
          }
        }


> 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-core
>    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 is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to