summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJohannes Dahlström <johannesd@vaadin.com>2015-07-10 15:19:36 +0300
committerTeemu Suo-Anttila <teemusa@vaadin.com>2015-07-15 08:59:30 +0000
commite288b0d159e4116b863836c4486a7bf289da16eb (patch)
tree1c8d30b8a2efed2f390ebacce86f3be5c7c0a5bc /server
parentae5793ae460cab22612c134cbec4b8ae6ed4175b (diff)
downloadvaadin-framework-e288b0d159e4116b863836c4486a7bf289da16eb.tar.gz
vaadin-framework-e288b0d159e4116b863836c4486a7bf289da16eb.zip
Prevent Grid editor move in unbuffered mode if validation errors in
fields Change-Id: I37f3c21f4464c8f83308a741ed51485f7bd0375a
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/ui/Grid.java39
1 files changed, 24 insertions, 15 deletions
diff --git a/server/src/com/vaadin/ui/Grid.java b/server/src/com/vaadin/ui/Grid.java
index 251ec0f678..f025b6e1c0 100644
--- a/server/src/com/vaadin/ui/Grid.java
+++ b/server/src/com/vaadin/ui/Grid.java
@@ -4129,28 +4129,37 @@ public class Grid extends AbstractFocusable implements SelectionNotifier,
@Override
public void bind(int rowIndex) {
- Exception exception = null;
try {
Object id = getContainerDataSource().getIdByIndex(rowIndex);
- if (!isEditorBuffered() || editedItemId == null) {
- editedItemId = id;
- }
- if (editedItemId.equals(id)) {
- doEditItem();
+ final boolean opening = editedItemId == null;
+
+ final boolean moving = !opening && !editedItemId.equals(id);
+
+ final boolean allowMove = !isEditorBuffered()
+ && getEditorFieldGroup().isValid();
+
+ if (opening || !moving || allowMove) {
+ doBind(id);
+ } else {
+ failBind(null);
}
} catch (Exception e) {
- exception = e;
+ failBind(e);
}
+ }
- if (exception != null) {
- handleError(exception);
- doCancelEditor();
- getEditorRpc().confirmBind(false);
- } else {
- doEditItem();
- getEditorRpc().confirmBind(true);
+ private void doBind(Object id) {
+ editedItemId = id;
+ doEditItem();
+ getEditorRpc().confirmBind(true);
+ }
+
+ private void failBind(Exception e) {
+ if (e != null) {
+ handleError(e);
}
+ getEditorRpc().confirmBind(false);
}
@Override
@@ -6004,7 +6013,7 @@ public class Grid extends AbstractFocusable implements SelectionNotifier,
if (!isEditorEnabled()) {
throw new IllegalStateException("Item editor is not enabled");
} else if (isEditorBuffered() && editedItemId != null) {
- throw new IllegalStateException("Editing item + " + itemId
+ throw new IllegalStateException("Editing item " + itemId
+ " failed. Item editor is already editing item "
+ editedItemId);
} else if (!getContainerDataSource().containsId(itemId)) {