diff options
author | Leif Åstrand <leif@vaadin.com> | 2015-02-06 11:34:20 +0200 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2015-02-06 11:34:20 +0200 |
commit | ee1fa835047a02f2982c7b8da9abf15b06c9c919 (patch) | |
tree | 75e2637ec49466313cfa2faf1cf2bd948db81095 /client | |
parent | 0e141e31bb30a0ab6726129f3c9fa892c92573e4 (diff) | |
download | vaadin-framework-ee1fa835047a02f2982c7b8da9abf15b06c9c919.tar.gz vaadin-framework-ee1fa835047a02f2982c7b8da9abf15b06c9c919.zip |
Show editor save error (#16602)
Change-Id: I2727a9fabef4291798e97495c2df86b077387cbb
Diffstat (limited to 'client')
3 files changed, 36 insertions, 15 deletions
diff --git a/client/src/com/vaadin/client/connectors/GridConnector.java b/client/src/com/vaadin/client/connectors/GridConnector.java index 60a730c80e..f8aa044a8d 100644 --- a/client/src/com/vaadin/client/connectors/GridConnector.java +++ b/client/src/com/vaadin/client/connectors/GridConnector.java @@ -228,13 +228,13 @@ public class GridConnector extends AbstractHasComponentsConnector implements @Override public void confirmBind(final boolean bindSucceeded) { - endRequest(bindSucceeded, null); + endRequest(bindSucceeded, null, null); } @Override public void confirmSave(boolean saveSucceeded, - List<String> errorColumnsIds) { - endRequest(saveSucceeded, errorColumnsIds); + String errorMessage, List<String> errorColumnsIds) { + endRequest(saveSucceeded, errorMessage, errorColumnsIds); } }); } @@ -303,7 +303,8 @@ public class GridConnector extends AbstractHasComponentsConnector implements currentRequest = request; } - private void endRequest(boolean succeeded, List<String> errorColumnsIds) { + private void endRequest(boolean succeeded, String errorMessage, + List<String> errorColumnsIds) { assert currentRequest != null : "Current request was null"; /* * Clear current request first to ensure the state is valid if @@ -324,7 +325,7 @@ public class GridConnector extends AbstractHasComponentsConnector implements errorColumns = null; } - request.failure(errorColumns); + request.failure(errorMessage, errorColumns); } } } diff --git a/client/src/com/vaadin/client/widget/grid/EditorHandler.java b/client/src/com/vaadin/client/widget/grid/EditorHandler.java index 1d152c708c..970130737c 100644 --- a/client/src/com/vaadin/client/widget/grid/EditorHandler.java +++ b/client/src/com/vaadin/client/widget/grid/EditorHandler.java @@ -86,12 +86,16 @@ public interface EditorHandler<T> { * Informs Grid that an error occurred while trying to process the * request. * + * @param errorMessage + * and error message to show to the user, or + * <code>null</code> to not show any message. * @param errorColumns * a collection of columns for which an error indicator * should be shown, or <code>null</code> if no columns should * be marked as erroneous. */ - public void failure(Collection<Grid.Column<?, T>> errorColumns); + public void failure(String errorMessage, + Collection<Grid.Column<?, T>> errorColumns); /** * Checks whether the request is completed or not. @@ -107,8 +111,8 @@ public interface EditorHandler<T> { * <p> * The implementation <em>must</em> call either * {@link EditorRequest#success()} or - * {@link EditorRequest#failure(Collection)} to signal a successful or a - * failed (respectively) bind action. + * {@link EditorRequest#failure(String, Collection)} to signal a successful + * or a failed (respectively) bind action. * * @param request * the data binding request @@ -123,9 +127,10 @@ public interface EditorHandler<T> { * <p> * In contrast to {@link #bind(EditorRequest)} and * {@link #save(EditorRequest)}, any calls to - * {@link EditorRequest#success()} or {@link EditorRequest#fail()} have no - * effect on the outcome of the cancel action. The editor is already closed - * when this method is called. + * {@link EditorRequest#success()} or + * {@link EditorRequest#failure(String, Collection)} have no effect on the + * outcome of the cancel action. The editor is already closed when this + * method is called. * * @param request * the cancel request diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index 0f3ffc696a..9a6a6d6029 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -998,13 +998,16 @@ public class Grid<T> extends ResizeComposite implements return w; } - private void complete(Collection<Column<?, T>> errorColumns) { + private void complete(String errorMessage, + Collection<Column<?, T>> errorColumns) { if (completed) { throw new IllegalStateException( "An EditorRequest must be completed exactly once"); } completed = true; + grid.getEditor().setErrorMessage(errorMessage); + grid.getEditor().clearEditorColumnErrors(); if (errorColumns != null) { for (Column<?, T> column : errorColumns) { @@ -1015,15 +1018,16 @@ public class Grid<T> extends ResizeComposite implements @Override public void success() { - complete(null); + complete(null, null); if (callback != null) { callback.onSuccess(this); } } @Override - public void failure(Collection<Grid.Column<?, T>> errorColumns) { - complete(errorColumns); + public void failure(String errorMessage, + Collection<Grid.Column<?, T>> errorColumns) { + complete(errorMessage, errorColumns); if (callback != null) { callback.onError(this); } @@ -1179,6 +1183,17 @@ public class Grid<T> extends ResizeComposite implements }); } + public void setErrorMessage(String errorMessage) { + if (errorMessage == null) { + message.removeFromParent(); + } else { + message.setInnerText(errorMessage); + if (message.getParentElement() == null) { + messageWrapper.appendChild(message); + } + } + } + public int getRow() { return rowIndex; } |