aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/src/com/vaadin/ui/Grid.java19
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/grid/GridColumns.java9
2 files changed, 23 insertions, 5 deletions
diff --git a/server/src/com/vaadin/ui/Grid.java b/server/src/com/vaadin/ui/Grid.java
index d77c6411ef..ab27a141b7 100644
--- a/server/src/com/vaadin/ui/Grid.java
+++ b/server/src/com/vaadin/ui/Grid.java
@@ -2154,11 +2154,20 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
public Column setSortable(boolean sortable) {
checkColumnIsAttached();
- if (sortable && !(grid.datasource instanceof Sortable)) {
- throw new IllegalStateException(
- "Can't set column "
- + toString()
- + " sortable. The Container of Grid does not implement Sortable");
+ if (sortable) {
+ if (!(grid.datasource instanceof Sortable)) {
+ throw new IllegalStateException(
+ "Can't set column "
+ + toString()
+ + " sortable. The Container of Grid does not implement Sortable");
+ } else if (!((Sortable) grid.datasource)
+ .getSortableContainerPropertyIds().contains(propertyId)) {
+ throw new IllegalStateException(
+ "Can't set column "
+ + toString()
+ + " sortable. Container doesn't support sorting by property "
+ + propertyId);
+ }
}
state.sortable = sortable;
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 4501fc8e39..5e96f4eeae 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
@@ -57,6 +57,7 @@ public class GridColumns {
for (int c = 0; c < 10; c++) {
ds.addContainerProperty("column" + c, String.class, "");
}
+ ds.addContainerProperty("noSort", Object.class, null);
grid = new Grid(ds);
getStateMethod = Grid.class.getDeclaredMethod("getState");
@@ -233,6 +234,14 @@ public class GridColumns {
grid.removeColumn("banana phone");
}
+ @Test(expected = IllegalStateException.class)
+ public void testSetNonSortableColumnSortable() {
+ Column noSortColumn = grid.getColumn("noSort");
+ assertFalse("Object property column should not be sortable.",
+ noSortColumn.isSortable());
+ noSortColumn.setSortable(true);
+ }
+
private GridColumnState getColumnState(Object propertyId) {
String columnId = columnIdMapper.key(propertyId);
for (GridColumnState columnState : state.columns) {