I have a simple panel (the panel itself is part of bigger form) with CheckGroup. The checkboxes in the check group are generated in the list view component. I need to dynamicaly change this panel and upon every change I need to retrieve the selected items. The code of the panel basically looks like this:
CheckGroup<MyObject> group = new CheckGroup<MyObject>(ID, selectedObjects);
ListView<MyObject> objectList = new ListView<MyObject>(ID, values) {
@Override
protected void populateItem(ListItem<MyObject> item) {
Check<MyObject> check = new Check<MyObject>(TIME_CHECK, item.getModel());
Label l = new Label(TIME_LABEL, item.getModel());
item.add(check);
item.add(l);
}
}
group.add(objectList);
group.add(new AjaxFormChoiceComponentUpdatingBehavior() {
@Override
protected void onUpdate(AjaxRequestTarget target) {
System.out.println("Selected objects: "+selectedObjects.size());
}
});
add(group);
Now, the problem is, whenever I click on the check box, the two identical objects are added to the selectedObjects
list. And if I remove the AjaxFormChoiceComponentUpdatingBehavior
, no objects are added to the list (which make sense, because I'm not submiting the form at this point).
I'm not exactly sure how to solve this problem and the best solution I came up with was getting the list and the going through it, removing duplicities.
Also, sorry for the title, but I have no idea how to name this problem.
Here's a little example to clarify the problem: Lets say the check group is displaying these objects:
object 1
object 2
object 3
object 4
object 5
Then when I select object 1
the model of check group (=selectedObjects) will look like this:
object 1
object 1
This was a bug on wicket. I used version 7.1 then changed on version 7.10 and the problem solved!