fixed bug in abstract mvc view
This commit is contained in:
@@ -51,6 +51,7 @@ import org.springframework.webflow.core.collection.ParameterMap;
|
||||
import org.springframework.webflow.definition.TransitionDefinition;
|
||||
import org.springframework.webflow.definition.TransitionableStateDefinition;
|
||||
import org.springframework.webflow.execution.Event;
|
||||
import org.springframework.webflow.execution.FlowExecutionKey;
|
||||
import org.springframework.webflow.execution.RequestContext;
|
||||
import org.springframework.webflow.execution.View;
|
||||
import org.springframework.webflow.expression.DefaultExpressionParserFactory;
|
||||
@@ -111,8 +112,11 @@ public abstract class AbstractMvcView implements View {
|
||||
model.putAll(flowScopes());
|
||||
exposeBindingModel(model);
|
||||
model.put("flowRequestContext", requestContext);
|
||||
model.put("flowExecutionKey", requestContext.getFlowExecutionContext().getKey().toString());
|
||||
model.put("flowExecutionUrl", requestContext.getFlowExecutionUrl());
|
||||
FlowExecutionKey key = requestContext.getFlowExecutionContext().getKey();
|
||||
if (key != null) {
|
||||
model.put("flowExecutionKey", requestContext.getFlowExecutionContext().getKey().toString());
|
||||
model.put("flowExecutionUrl", requestContext.getFlowExecutionUrl());
|
||||
}
|
||||
model.put("currentUser", requestContext.getExternalContext().getCurrentUser());
|
||||
try {
|
||||
doRender(model);
|
||||
|
||||
@@ -19,6 +19,8 @@ import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.servlet.View;
|
||||
import org.springframework.webflow.action.ViewFactoryActionAdapter;
|
||||
import org.springframework.webflow.engine.EndState;
|
||||
import org.springframework.webflow.engine.StubViewFactory;
|
||||
import org.springframework.webflow.engine.ViewState;
|
||||
import org.springframework.webflow.execution.RequestContext;
|
||||
@@ -69,6 +71,36 @@ public class MvcViewTests extends TestCase {
|
||||
assertNull(model.get(BindingResult.MODEL_KEY_PREFIX + "bindBean"));
|
||||
}
|
||||
|
||||
public void testRenderNoKey() throws Exception {
|
||||
MockRequestControlContext context = new MockRequestControlContext();
|
||||
EndState endState = new EndState(context.getRootFlow(), "end");
|
||||
endState.setFinalResponseAction(new ViewFactoryActionAdapter(new StubViewFactory()));
|
||||
context.setCurrentState(endState);
|
||||
context.getRequestScope().put("foo", "bar");
|
||||
context.getFlowScope().put("bar", "baz");
|
||||
context.getFlowScope().put("bindBean", new BindBean());
|
||||
context.getConversationScope().put("baz", "boop");
|
||||
context.getFlashScope().put("boop", "bing");
|
||||
context.getMockExternalContext().setCurrentUser("Keith");
|
||||
context.getMockExternalContext().setNativeContext(new MockServletContext());
|
||||
context.getMockExternalContext().setNativeRequest(new MockHttpServletRequest());
|
||||
context.getMockExternalContext().setNativeResponse(new MockHttpServletResponse());
|
||||
org.springframework.web.servlet.View mvcView = new MockView();
|
||||
AbstractMvcView view = new MockMvcView(mvcView, context);
|
||||
view.setFormatterRegistry(formatterRegistry);
|
||||
view.render();
|
||||
assertTrue(renderCalled);
|
||||
assertEquals("bar", model.get("foo"));
|
||||
assertEquals("baz", model.get("bar"));
|
||||
assertEquals("boop", model.get("baz"));
|
||||
assertEquals("bing", model.get("boop"));
|
||||
assertFalse(model.containsKey("flowExecutionKey"));
|
||||
assertFalse(model.containsKey("flowExecutionUrl"));
|
||||
assertEquals("Keith", ((Principal) model.get("currentUser")).getName());
|
||||
assertEquals(context, model.get("flowRequestContext"));
|
||||
assertNull(model.get(BindingResult.MODEL_KEY_PREFIX + "bindBean"));
|
||||
}
|
||||
|
||||
public void testRenderWithBindingModel() throws Exception {
|
||||
MockRequestControlContext context = new MockRequestControlContext();
|
||||
context.setCurrentState(new ViewState(context.getRootFlow(), "test", new StubViewFactory()));
|
||||
|
||||
Reference in New Issue
Block a user