diff options
author | Teemu Suo-Anttila <teemusa@vaadin.com> | 2015-01-16 13:13:22 +0200 |
---|---|---|
committer | Henrik Paul <henrik@vaadin.com> | 2015-01-20 11:37:11 +0000 |
commit | 74976a7ffcdd4ea3c19e799d16bf5430c6975420 (patch) | |
tree | 5bcb13baefe774461d3120027246e6007a01773b /server/src/com/vaadin/ui/Grid.java | |
parent | b9360a29a35a575c136da74f0f3e85a54990a121 (diff) | |
download | vaadin-framework-74976a7ffcdd4ea3c19e799d16bf5430c6975420.tar.gz vaadin-framework-74976a7ffcdd4ea3c19e799d16bf5430c6975420.zip |
Fix Editor creating fields before client Grid can attach them (#16214)
This patch includes some race condition handling.
Change-Id: I6ab3cf15a67de722181b2718ab85b6b4a6bcb997
Diffstat (limited to 'server/src/com/vaadin/ui/Grid.java')
-rw-r--r-- | server/src/com/vaadin/ui/Grid.java | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/server/src/com/vaadin/ui/Grid.java b/server/src/com/vaadin/ui/Grid.java index 999d75e99a..d77c6411ef 100644 --- a/server/src/com/vaadin/ui/Grid.java +++ b/server/src/com/vaadin/ui/Grid.java @@ -2740,14 +2740,19 @@ public class Grid extends AbstractComponent implements SelectionNotifier, @Override public void bind(int rowIndex) { - boolean success; + boolean success = false; try { Object id = getContainerDataSource().getIdByIndex(rowIndex); - doEditItem(id); - success = true; + if (editedItemId == null) { + editedItemId = id; + } + + if (editedItemId.equals(id)) { + success = true; + doEditItem(); + } } catch (Exception e) { handleError(e); - success = false; } getEditorRpc().confirmBind(success); } @@ -2764,13 +2769,12 @@ public class Grid extends AbstractComponent implements SelectionNotifier, @Override public void save(int rowIndex) { - boolean success; + boolean success = false; try { saveEditor(); success = true; } catch (Exception e) { handleError(e); - success = false; } getEditorRpc().confirmSave(success); } @@ -4474,31 +4478,31 @@ public class Grid extends AbstractComponent implements SelectionNotifier, * @param itemId * the id of the item to edit * @throws IllegalStateException - * if the editor is not enabled + * if the editor is not enabled or already editing an item * @throws IllegalArgumentException * if the {@code itemId} is not in the backing container * @see #setEditorEnabled(boolean) */ public void editItem(Object itemId) throws IllegalStateException, IllegalArgumentException { - doEditItem(itemId); - - getEditorRpc().bind(getContainerDataSource().indexOfId(itemId)); - } - - protected void doEditItem(Object itemId) { if (!isEditorEnabled()) { throw new IllegalStateException("Item editor is not enabled"); - } - - Item item = getContainerDataSource().getItem(itemId); - if (item == null) { + } else if (editedItemId != null) { + throw new IllegalStateException("Editing item + " + itemId + + " failed. Item editor is already editing item " + + editedItemId); + } else if (!getContainerDataSource().containsId(itemId)) { throw new IllegalArgumentException("Item with id " + itemId + " not found in current container"); } + editedItemId = itemId; + getEditorRpc().bind(getContainerDataSource().indexOfId(itemId)); + } + + protected void doEditItem() { + Item item = getContainerDataSource().getItem(editedItemId); editorFieldGroup.setItemDataSource(item); - editedItemId = itemId; for (Column column : getColumns()) { Object propertyId = column.getPropertyId(); |