Reputation: 3396
I have strange stacktrace when click to submit button (this code is rendered but don't work form processing). Example class:
public class SamplePage extends WebPage {
private List<String> list = Arrays.asList(new String[] { "item1", "item2", "item3" });
private List<String> selectedItem = Arrays.asList(new String[] { "item1" });
public SamplePage(final PageParameters parameters) {
super(parameters);
Form<?> form = new Form<Void>("form");
form.add(new Button("submin") {
@Override
public void onSubmit() {
System.out.println("Selected");
for (String tag : selectedItem)
System.out.println(tag);
}
});
ListMultipleChoice<String> selector = new ListMultipleChoice<>("itemSelector",
new PropertyModel<List<String>>(this, "selectedItem"), list);
add(form);
form.add(selector);
}
public List<String> getSelectedItem() {
return selectedItem;
}
public void setSelectedItem(List<String> selectedItem) {
this.selectedItem = selectedItem;
}
}
Caused by: java.lang.UnsupportedOperationException
at java.util.AbstractList.remove(AbstractList.java:161)
at java.util.AbstractList$Itr.remove(AbstractList.java:374)
at java.util.AbstractList.removeRange(AbstractList.java:571)
at java.util.AbstractList.clear(AbstractList.java:234)
at org.apache.wicket.markup.html.form.FormComponent.updateCollectionModel(FormComponent.java:1531)
at org.apache.wicket.markup.html.form.ListMultipleChoice.updateModel(ListMultipleChoice.java:369)
at org.apache.wicket.markup.html.form.Form$FormModelUpdateVisitor.component(Form.java:221)
at org.apache.wicket.markup.html.form.Form$FormModelUpdateVisitor.component(Form.java:192)
at org.apache.wicket.util.visit.Visits.visitPostOrderHelper(Visits.java:273)
at org.apache.wicket.util.visit.Visits.visitPostOrderHelper(Visits.java:261)
at org.apache.wicket.util.visit.Visits.visitPostOrder(Visits.java:244)
at org.apache.wicket.markup.html.form.FormComponent.visitComponentsPostOrder(FormComponent.java:388)
at org.apache.wicket.markup.html.form.Form.internalUpdateFormComponentModels(Form.java:1701)
at org.apache.wicket.markup.html.form.Form.updateFormComponentModels(Form.java:1666)
at org.apache.wicket.markup.html.form.Form.process(Form.java:827)
at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:762)
at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:692)
... 31 more
How I understand problem is in definition model, but I don't understand why (I tried a lot of ways and didn't check problem). When I created DropDownChoice in same way, all worked correctly, but in this case I used
new PropertyModel<String>(this, "field")
in contrast to
new PropertyModel<List<String>>(this, "selectedItem")
I think it's very silly mistake and ask your help.
Upvotes: 0
Views: 1157
Reputation: 7696
Without actually trying it out, but I guess that the List implementation you get from Arrays.asList() does not support removal of entries in the list.
Try something along the lines:
private List<String> selectedItem =
new LinkedList(Arrays.asList(new String[] { "item1")});
E.g. use an Implementation that allows removal. Wicket needs to modify the entries in the list to reflet the selected items.
Hope that helps. Bert
Upvotes: 2
Reputation: 5681
Arrays.asList() returns a fixed size list, you (i.e. Wicket) cannot remove elements form it.
Use another list instead:
private List<String> selectedItem = new ArrayList<String>();
public SamplePage(final PageParameters parameters) {
....
selectedItem.add("item1");
Upvotes: 4