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; } } }