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

Emond Papegaaij commented on WICKET-6569:
-----------------------------------------

I agree with Michael that the overloaded methods are very inconvenient. For 
example, take this piece of code:
{code}
public class DomainObject {
  private String value;
  public String getValue() {return value;}
  public DomainObject setValue(String value) {this.value = value; return this;}
}

DomainObject obj = new DomainObject();
LambdaModel.of(obj::getValue, obj::setValue);
{code}

This will use the method with an IModel and Function, resulting in a readonly 
{{IModel<DomainObject>}} that always returns {{obj}}. Now if I change the 
setter to return {{void}} or use this cast {{LambdaModel.of(obj::getValue, 
(SerializableConsumer<String>) obj::setValue)}} I get an {{IModel<String>}} 
that reflects the {{value}} property. Moreover, javac is having trouble with 
these invocations and often cannot resolve the method (I think this is a bug in 
javac though and it might have been fixed in more recent versions, haven't 
tested this for a while). 

In fact, the method {{public static <X, R> IModel<R> of(IModel<X> target, 
SerializableFunction<X, R> getter)}} is superfluous, as it gives you exactly 
the same model as IModel.map. I'm not sure what we should do with this method 
in 8, but I'd rather see it removed in 9.

> LambdaModel.of overload is ambiguous
> ------------------------------------
>
>                 Key: WICKET-6569
>                 URL: https://issues.apache.org/jira/browse/WICKET-6569
>             Project: Wicket
>          Issue Type: Wish
>          Components: wicket
>    Affects Versions: 8.0.0
>            Reporter: Michael Gerhards
>            Priority: Minor
>         Attachments: myproject.zip
>
>   Original Estimate: 4h
>  Remaining Estimate: 4h
>
> a method call of
> LambdaModel.of(this::getModelObject, this::setModelObject)
> refers to
> public static <X, R> IModel<R> of(IModel<X> target, SerializableFunction<X, 
> R> getter)
> but should be
> public static <R> IModel<R> of(SerializableSupplier<R> getter, 
> SerializableConsumer<R> setter)
> The problem is that IModel and SerializableSupplier have functionally the 
> same interface:
> T getObject(); vs. T get();
>  
> Background:
> The child component should share its default model object with its parent 
> component's default model object. So if setDefaultModelObject is called on 
> the parent component than the child component should also refer to the new 
> value (and with versa).
>  
> Workaround:
> public Parent(String wicektId, IModel<Role> roleModel) {
> IModel<Role> childRoleModel = new IModel<Role>() {
>              @Override
>              public Role getObject()
> {                 return Parent.this.getModelObject();             }
>             @Override
>              public void setObject(Role object)
> {                 Parent.this.setModelObject(object);             }
>  };
> add(new Child("child", childRoleModel));
> }
>  
> Solution:
> The problem only exists because .of Method is overloaded. If both methods 
> would have different names (or be in different classes) than the compiler 
> would be fine.
>  
> Please see attached files



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to