From 93d30c28021caccf1f416330875c40fc65e28ed4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20Kr=C3=BCger?= Date: Thu, 2 Mar 2017 22:12:42 +0100 Subject: [PATCH] Adjust handling of resolved action command object When the view provider's getViewName() method is called twice with the same viewAndParameters argument, the corresponding result is returned right away for the second invocation if an action command object was determined in the first invocation. An exception will only be thrown if there is already a view object available but has not yet been requested via getView() and a different viewAndParameters argument is passed into getViewName(). This fixes an issue which the add-on had with Vaadin 7.7 and 8.0. --- .../uriactions/ActionExecutionView.java | 10 +++--- .../UriFragmentActionNavigatorWrapper.java | 35 +++++++++++-------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/vaadin/uriactions/ActionExecutionView.java b/src/main/java/org/vaadin/uriactions/ActionExecutionView.java index b60f9ce..3d87e59 100644 --- a/src/main/java/org/vaadin/uriactions/ActionExecutionView.java +++ b/src/main/java/org/vaadin/uriactions/ActionExecutionView.java @@ -19,19 +19,17 @@ */ public class ActionExecutionView implements View { private final UriActionCommand command; - private final UriFragmentActionNavigatorWrapper uriFragmentActionNavigatorWrapper; - ActionExecutionView(final UriFragmentActionNavigatorWrapper uriFragmentActionNavigatorWrapper, final UriActionCommand command) { - Preconditions.checkNotNull(command); - Preconditions.checkNotNull(uriFragmentActionNavigatorWrapper); + ActionExecutionView(final UriActionCommand command) { + if (command == null) { + throw new IllegalArgumentException("action command object must not be null"); + } this.command = command; - this.uriFragmentActionNavigatorWrapper = uriFragmentActionNavigatorWrapper; } @Override public void enter(final ViewChangeListener.ViewChangeEvent event) { command.run(); - uriFragmentActionNavigatorWrapper.resetCurrentActionCommand(); } /** diff --git a/src/main/java/org/vaadin/uriactions/UriFragmentActionNavigatorWrapper.java b/src/main/java/org/vaadin/uriactions/UriFragmentActionNavigatorWrapper.java index b579d75..ebeaccd 100644 --- a/src/main/java/org/vaadin/uriactions/UriFragmentActionNavigatorWrapper.java +++ b/src/main/java/org/vaadin/uriactions/UriFragmentActionNavigatorWrapper.java @@ -87,7 +87,6 @@ public class UriFragmentActionNavigatorWrapper { */ private final Navigator navigator; private UriActionMapperTree uriActionMapperTree; - private UriActionCommand currentActionCommandObject; private Object routingContext; /** @@ -197,13 +196,6 @@ public void setRoutingContext(final Object routingContext) { this.routingContext = routingContext; } - /** - * Sets the current action command object to null. - */ - void resetCurrentActionCommand() { - currentActionCommandObject = null; - } - /** * {@link ViewDisplay} which delegates the task to display the current {@link View} to a wrapped {@link ViewDisplay} * if the {@link View} to be shown is not of type {@link ActionExecutionView}. The wrapped {@link @@ -232,24 +224,39 @@ public void showView(final View view) { * fragment could successfully be resolved. */ private class UriActionViewProvider implements ViewProvider { + private ActionExecutionView currentView; + private String currentNavigationState; + @Override public String getViewName(final String viewAndParameters) { if (uriActionMapperTree == null) { return null; } + if (currentView != null && currentNavigationState != null) { + if (currentNavigationState.equals(viewAndParameters)) { + return viewAndParameters; + } else { + throw new IllegalStateException( + "Access synchronization problem: this action navigator is currently handling another request. " + + "Currently handled navigation state is: " + currentNavigationState + + ". Current action is: " + currentView.getUriActionCommand()); + } + } + final UriActionCommand action = uriActionMapperTree.interpretFragment(viewAndParameters, routingContext, false); - if (currentActionCommandObject != null) { - throw new IllegalStateException( - "Thread synchronization problem: this action navigator is currently handling another request. Current action is: " - + currentActionCommandObject); + if (action != null) { + currentView = new ActionExecutionView(action); + currentNavigationState = viewAndParameters; } - currentActionCommandObject = action; return action != null ? viewAndParameters : null; } @Override public View getView(final String viewName) { - return new ActionExecutionView(UriFragmentActionNavigatorWrapper.this, currentActionCommandObject); + View returnedView = currentView; + currentNavigationState = null; + currentView = null; + return returnedView; } } }