Skip to content

Commit

Permalink
Adjust handling of resolved action command object
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rolandkrueger committed Mar 2, 2017
1 parent 583bd53 commit 93d30c2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
10 changes: 4 additions & 6 deletions src/main/java/org/vaadin/uriactions/ActionExecutionView.java
Expand Up @@ -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();
}

/**
Expand Down
Expand Up @@ -87,7 +87,6 @@ public class UriFragmentActionNavigatorWrapper {
*/
private final Navigator navigator;
private UriActionMapperTree uriActionMapperTree;
private UriActionCommand currentActionCommandObject;
private Object routingContext;

/**
Expand Down Expand Up @@ -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 <em>not</em> of type {@link ActionExecutionView}. The wrapped {@link
Expand Down Expand Up @@ -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;
}
}
}

0 comments on commit 93d30c2

Please sign in to comment.