Browse Source

Make CheckBoxGroup.SimpleMultiSelectModel return a selection copy #293.

getSelectedItems() must return a copy to fulfill the contract specified 
in SelectionModel: it must be a snapshot of the current state and safe
to iterate over while changing selection.

Change-Id: Ie2f15eb626dd80df2036bcb2d4e9387fc31389c9
tags/8.0.0.alpha3
Denis Anisimov 7 years ago
parent
commit
3db7de6eac

+ 1
- 1
server/src/main/java/com/vaadin/ui/CheckBoxGroup.java View File

@@ -71,7 +71,7 @@ public class CheckBoxGroup<T> extends AbstractMultiSelect<T> {

@Override
public Set<T> getSelectedItems() {
return Collections.unmodifiableSet(selection);
return Collections.unmodifiableSet(new LinkedHashSet<>(selection));
}

@Override

+ 14
- 0
server/src/test/java/com/vaadin/data/BinderMultiSelectTest.java View File

@@ -117,6 +117,20 @@ public class BinderMultiSelectTest
assertEquals(Collections.singleton(TestEnum.TWO), item.getEnums());
}

@Test
public void bound_setSelection_beanValueIsACopy() {
bindEnum();

select.select(TestEnum.TWO);

Set<TestEnum> enums = item.getEnums();

binder.bind(new BeanWithEnums());
select.select(TestEnum.ONE);

assertEquals(Collections.singleton(TestEnum.TWO), enums);
}

@Test
public void bound_deselect_beanValueUpdatedToNull() {
item.setEnums(Collections.singleton(TestEnum.ONE));

Loading…
Cancel
Save