diff options
-rw-r--r-- | server/src/com/vaadin/ui/Grid.java | 10 | ||||
-rw-r--r-- | server/tests/src/com/vaadin/tests/server/component/grid/GridColumns.java | 5 |
2 files changed, 14 insertions, 1 deletions
diff --git a/server/src/com/vaadin/ui/Grid.java b/server/src/com/vaadin/ui/Grid.java index 175c326f14..18d45b3b9f 100644 --- a/server/src/com/vaadin/ui/Grid.java +++ b/server/src/com/vaadin/ui/Grid.java @@ -3116,8 +3116,16 @@ public class Grid extends AbstractComponent implements SelectionNotifier, * * @param propertyId * The property id of column to be removed + * + * @throws IllegalArgumentException + * if there is no column for given property id in this grid */ - public void removeColumn(Object propertyId) { + public void removeColumn(Object propertyId) throws IllegalArgumentException { + if (!columns.keySet().contains(propertyId)) { + throw new IllegalArgumentException( + "There is no column for given property id " + propertyId); + } + List<Column> removed = new ArrayList<Column>(); removed.add(getColumn(propertyId)); internalRemoveColumn(propertyId); diff --git a/server/tests/src/com/vaadin/tests/server/component/grid/GridColumns.java b/server/tests/src/com/vaadin/tests/server/component/grid/GridColumns.java index 1204b1e396..4501fc8e39 100644 --- a/server/tests/src/com/vaadin/tests/server/component/grid/GridColumns.java +++ b/server/tests/src/com/vaadin/tests/server/component/grid/GridColumns.java @@ -228,6 +228,11 @@ public class GridColumns { } } + @Test(expected = IllegalArgumentException.class) + public void testRemoveColumnThatDoesNotExist() { + grid.removeColumn("banana phone"); + } + private GridColumnState getColumnState(Object propertyId) { String columnId = columnIdMapper.key(propertyId); for (GridColumnState columnState : state.columns) { |