ListMultipleChoice: updateModel method looses the value submitted from the
select control
------------------------------------------------------------------------------------------
Key: WICKET-2811
URL: https://issues.apache.org/jira/browse/WICKET-2811
Project: Wicket
Issue Type: Bug
Components: wicket
Affects Versions: 1.4.6
Reporter: Anton Vodonosov
ListMultipleChoice looses the value submitted from client in certain
conditions.
This is because the collection returned by convertInput() is passed to
model.setObject(); and later, when the model is modified, converted input is
affected too. (see ListMultipleChoice.java, line 344 in svn revision 929271).
Simple page reproducing this bug under wicket 1.4.6 attached.
Key points in the code, required to reproduce the problem:
1. The Form component is wrapped by a Border component
2. The model used flor ListMultipleChoice initially returns null from the
getObject() method.
To see the error open the attached page in browser, select something in the
list, press Submit.
Resulting message in the feedback panel will be: "submitted values: []", i.e.
the the submit handler sees empty list in the model.
Expected: submit handler must see list of the values selected in the list by
user.
The reason of the error:
1. Method Form.internalUpdateFormComponentModels() in Wicket 1.4.6 calls
ListMultipleChoice.updateModel
two times when the form is wrapped by a border:
private void internalUpdateFormComponentModels()
{
FormComponent.visitComponentsPostOrder(this, new
FormModelUpdateVisitor(this));
MarkupContainer border = findParent(Border.class);
if (border != null)
{
FormComponent.visitComponentsPostOrder(border, new
FormModelUpdateVisitor(this));
}
}
2. On the first call of the ListMultipleChoice.updateModel the result of
getConvertedInput() is stored in the model (line 344).
Now model and getConvertedInput() share the same collection.
On the second call, the collection retrieved from model is cleared (line
326), and then getConvertedInput() is used
again (but now returns empty collection)
314 public void updateModel()
315 {
316 Collection<T> selectedValues = getModelObject();
317 if (selectedValues != null)
318 {
...
326 selectedValues.clear();
327 selectedValues.addAll(getConvertedInput());
...
340 }
341 else
342 {
343 selectedValues = getConvertedInput();
344 setDefaultModelObject(selectedValues);
345 }
346 }
I would suggest to not share the collection between getConvertedInput() and the
model:
343 selectedValues = getConvertedInput();
selectedValues = new
ArrayList<T>(selectedValues);
344 setDefaultModelObject(selectedValues);
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.