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

ivaynberg edited comment on WICKET-1331 at 2/11/08 2:40 PM:
----------------------------------------------------------------

you are using the component in a manner we consider incorrect.

in 1.4 the component will be generified as:

DropDownChoice<T>(String id, IModel<T> model, IModel<List<T>> choices, 
IChoiceRenderer<T> renderer)

how will your change work than??? last time i checked your ChoiceOption doesnt 
not extend Long.

anyways, this is the last time i am replying here, as i have mentioned you are 
free to start an email thread on our dev list, that is much better for 
discussions.

====================================================================

also looking at your code, your implementation of ChoiceOption.equlas() is 
horribly broken and would be considered as an ugly hack by any experienced 
developer

one of key equals contracts is symmetry. that meas if a.equals(b) is true, then 
so is b.equals(a)

in your case choiceoption.equals(long(5)) might be true, but never 
5l.equals(choiceoption)

thus your equals implementation is flawed, i urge you to read Object.equals() 
javadoc.

      was (Author: ivaynberg):
    you are using the component in a manner we consider incorrect.

in 1.4 the component will be generified as:

DropDownChoice<T>(String id, IModel<T> model, IModel<List<T>> choices, 
IChoiceRenderer<T> renderer)

how will your change work than??? last time i checked your ChoiceOption doesnt 
not extend Long.

anyways, this is the last time i am replying here, as i have mentioned you are 
free to start an email thread on our dev list, that is much better for 
discussions.
  
> getModelValue() in AbstractSingleSelectChoice and ListMultipleChoice can't 
> handle complex list items type correctly
> -------------------------------------------------------------------------------------------------------------------
>
>                 Key: WICKET-1331
>                 URL: https://issues.apache.org/jira/browse/WICKET-1331
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 1.3.0-final, 1.3.1
>         Environment: Suse 10.3, JRE 1.6 (1.6.0_04-b12), jetty 6.1.7
>            Reporter: Sergiy Yevtushenko
>            Assignee: Igor Vaynberg
>         Attachments: testproject.zip
>
>   Original Estimate: 0.5h
>  Remaining Estimate: 0.5h
>
> AbstractSingleSelectChoice.getModelValue() implementation uses List.indexOf() 
> to find the key and this causes problems if list of choices contains complex 
> values rather than simple list of String instances. In this case indexOf() 
> returns -1 and this can't be resolved by overriding equals() for list 
> elements. This happens because internally AbstractList.indexOf() invokes 
> equals() method of passed key value passing it list items as a parameter. 
> Also, current implementation may pass key returned by getModelObject() to 
> IChoiceRender, while it expects values from list of items. Correct 
> implementation of this method may look so:
> -------------------------
>       public String getModelValue()
>       {
>               // @@ Modified by SIY
>               Object object = getModelObject();
>               if (object != null)
>               {
>                       // compare choice items with given keys and pass down
>                       // to IChoiceRenderer list item rather than key
>                       Iterator iter = getChoices().iterator();
>                       int i = 0;
>                       while (iter.hasNext())
>                       {
>                               Object obj = iter.next();
>                               if (obj != null && obj.equals(object))
>                               {
>                                       object = obj;
>                                       break;
>                               }
>                               i++;
>                       }
>                       if (i > getChoices().size())
>                               i = -1;
>                       return getChoiceRenderer().getIdValue(object, i);
>               }
>               return NO_SELECTION_VALUE;
>       }
> -----------------------------------
> Similar issues also present in ListMultipleChoice.getModelValue(), but they 
> can't be resolved by overriding this method in subclass because this method 
> declared final.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to