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

Martin Grigorov commented on WICKET-3496:
-----------------------------------------

I think using getDefaultModelObject() is the correct one in this case.
Using getInnermostModel() totally ignores the wrapping model and this will be 
quite confusing for the client application.

> 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