[ 
https://issues.apache.org/jira/browse/WICKET-2465?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Pedro Santos updated WICKET-2465:
---------------------------------


Exactly, sorry for the call. The list was referenced by other object that 
operate on it too, breaking the expected component behavior, that was not 
operating on a stable list.

> ListMultipleChoice - convertChoiceIdsToChoices
> ----------------------------------------------
>
>                 Key: WICKET-2465
>                 URL: https://issues.apache.org/jira/browse/WICKET-2465
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 1.4.1
>         Environment: tomcat 6
>            Reporter: Pedro Santos
>
> The method convertChoiceIdsToChoices on ListMultipleChoice has to converts 
> submitted choice ids to choice objects.
> Bug: it do not resolve my second selection on component correctly.
> Ex: I have an list with items a, b, c, d.
> 1 - select item "a"
> 1.1 ListMultipleChoice component receive a collection,  containing the choice 
> "a" object, on model.
> 2 - select item "b"
> 2.1 ListMultipleChoice component receive an empty collection on model.
> simple debugging the component convertInput process, I do discover that the 
> problem is occurring cause the method convertChoiceIdsToChoices is comparing 
> an wrong 'old selected choice IdValue' with an 'right received choice id'. At 
> line 291:
>                     if (getChoiceRenderer().getIdValue(choice, 
> index).equals(ids[i]))
> the index variable passed to IChoiceRenderer, do not reflect the original 
> index of the old choice, so the choice IdValue reached to old selection are 
> wrong. The value reached id only his index on the "choices"( List variable). 
> On this way, the comparison with "ids[i]", that reflect the 'right received 
> choice id'  fails.
>       protected List<T> convertChoiceIdsToChoices(String[] ids)
>       {
>               ArrayList<T> selectedValues = new ArrayList<T>();
>               // If one or more ids is selected
>               if (ids != null && ids.length > 0 && !Strings.isEmpty(ids[0]))
>               {
>                       // Get values that could be selected
>                       final List<? extends T> choices = getChoices();
>                       // Loop through selected indices
>                       for (int i = 0; i < ids.length; i++)
>                       {
>                               for (int index = 0; index < choices.size(); 
> index++)
>                               {
>                                       // Get next choice
>                                       final T choice = choices.get(index);
>                                       if 
> (getChoiceRenderer().getIdValue(choice, index).equals(ids[i]))
>                                       {
>                                               selectedValues.add(choice);
>                                               break;
>                                       }
>                               }
>                       }
>               }
>               return selectedValues;
>       }

-- 
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