protected Event doExecute(RequestContext context) throws Exception { if (viewFactory != null) { viewFactory.getView(context).render(); } return new Event(this, "success"); } }
private boolean handleEvent(View view, RequestControlContext context) { view.processUserEvent(); if (view.hasFlowEvent()) { Event event = view.getFlowEvent(); if (logger.isDebugEnabled()) { logger.debug("Event '" + event.getId() + "' returned from view " + view); } return context.handleEvent(event); } else { return false; } }
View view = viewFactory.getView(context); context.setCurrentView(view); if (view.userEventQueued()) { boolean stateExited = handleEvent(view, context); if (!stateExited) { if (externalContext.isResponseComplete()) { if (externalContext.isResponseCompleteFlowExecutionRedirect()) { context.getFlashScope().put(View.USER_EVENT_STATE_ATTRIBUTE, view.getUserEventState()); } else { clearFlash(context); } else { if (shouldRedirectInSameState(context)) { context.getFlashScope().put(View.USER_EVENT_STATE_ATTRIBUTE, view.getUserEventState()); externalContext.requestFlowExecutionRedirect(); } else {
public void testProcessUserEventNoEvent() throws IOException { TestAction action = new TestAction(); ActionExecutingViewFactory factory = new ActionExecutingViewFactory(action); MockRequestContext context = new MockRequestContext(); View view = factory.getView(context); assertFalse(action.isExecuted()); view.render(); assertTrue(action.isExecuted()); view.processUserEvent(); assertFalse(view.hasFlowEvent()); assertNull(view.getFlowEvent()); } }
/** * Ajax Request - View already exists in view/flash scope and must be restored and the lifecycle executed, no flow * event signaled */ public final void testGetView_Restore_Ajax() { this.lifecycle = new NoExecutionLifecycle(this.jsfMock.lifecycle()); this.factory = new JsfViewFactory(this.parser.parseExpression(VIEW_ID, new FluentParserContext().template().evaluate(RequestContext.class).expectResult(String.class)), this.lifecycle); MockUIViewRoot existingRoot = new MockUIViewRoot(); existingRoot.setViewId(VIEW_ID); ((MockViewHandler) this.viewHandler).setRestoreView(existingRoot); this.request.addHeader("Accept", "text/html;type=ajax"); EasyMock.expect(this.context.getCurrentState()).andReturn(new NormalViewState()); this.context.inViewState(); EasyMock.expectLastCall().andReturn(true); EasyMock.replay(this.context); View restoredView = this.factory.getView(this.context); assertNotNull("A View was not restored", restoredView); assertTrue("A JsfView was expected", restoredView instanceof JsfView); assertTrue("An ViewRoot was not set", ((JsfView) restoredView).getViewRoot() != null); assertEquals("View name did not match", VIEW_ID, ((JsfView) restoredView).getViewRoot().getViewId()); assertFalse("An unexpected event was signaled,", restoredView.hasFlowEvent()); assertTrue("The PostRestoreViewEvent was not seen", existingRoot.isPostRestoreStateEventSeen()); }
private void updateHistory(RequestControlContext context) { TransitionDefinition transition = context.getCurrentTransition(); History history = (History) transition.getAttributes().get("history"); if (history == null || history == History.PRESERVE) { View currentView = context.getCurrentView(); if (currentView != null && shouldRedirect(context)) { currentView.saveState(); } context.updateCurrentFlowExecutionSnapshot(); } else if (history == History.DISCARD) { context.removeCurrentFlowExecutionSnapshot(); } else if (history == History.INVALIDATE) { context.removeAllFlowExecutionSnapshots(); } }
public void testProcessUserEvent() throws IOException { TestAction action = new TestAction(); ActionExecutingViewFactory factory = new ActionExecutingViewFactory(action); MockRequestContext context = new MockRequestContext(); View view = factory.getView(context); assertFalse(action.isExecuted()); view.render(); assertTrue(action.isExecuted()); context.putRequestParameter("_eventId", "foo"); view.processUserEvent(); assertTrue(view.hasFlowEvent()); assertEquals("foo", view.getFlowEvent().getId()); }
/** * View has not yet been created */ public final void testGetView_Create() { this.lifecycle = new NoExecutionLifecycle(this.jsfMock.lifecycle()); this.factory = new JsfViewFactory(this.parser.parseExpression(VIEW_ID, new FluentParserContext().template().evaluate(RequestContext.class).expectResult(String.class)), this.lifecycle); MockUIViewRoot newRoot = new MockUIViewRoot(); newRoot.setViewId(VIEW_ID); ((MockViewHandler) this.viewHandler).setCreateView(newRoot); this.context.inViewState(); EasyMock.expectLastCall().andReturn(true); EasyMock.replay(this.context); View newView = this.factory.getView(this.context); assertNotNull("A View was not created", newView); assertTrue("A JsfView was expected", newView instanceof JsfView); assertEquals("View name did not match", VIEW_ID, ((JsfView) newView).getViewRoot().getViewId()); assertFalse("An unexpected event was signaled,", newView.hasFlowEvent()); }
private void updateHistory(RequestControlContext context) { TransitionDefinition transition = context.getCurrentTransition(); History history = (History) transition.getAttributes().get("history"); if (history == null || history == History.PRESERVE) { View currentView = context.getCurrentView(); if (currentView != null && shouldRedirect(context)) { currentView.saveState(); } context.updateCurrentFlowExecutionSnapshot(); } else if (history == History.DISCARD) { context.removeCurrentFlowExecutionSnapshot(); } else if (history == History.INVALIDATE) { context.removeAllFlowExecutionSnapshots(); } }
public void testProcessUserEventButton() throws IOException { TestAction action = new TestAction(); ActionExecutingViewFactory factory = new ActionExecutingViewFactory(action); MockRequestContext context = new MockRequestContext(); View view = factory.getView(context); assertFalse(action.isExecuted()); view.render(); assertTrue(action.isExecuted()); context.putRequestParameter("_eventId_foo", "doesn't matter"); view.processUserEvent(); assertTrue(view.hasFlowEvent()); assertEquals("foo", view.getFlowEvent().getId()); }
private boolean handleEvent(View view, RequestControlContext context) { view.processUserEvent(); if (view.hasFlowEvent()) { Event event = view.getFlowEvent(); if (logger.isDebugEnabled()) { logger.debug("Event '" + event.getId() + "' returned from view " + view); } return context.handleEvent(event); } else { return false; } }
private void render(RequestControlContext context, View view) throws ViewRenderingException { if (logger.isDebugEnabled()) { logger.debug("Rendering + " + view); logger.debug(" Flash scope = " + context.getFlashScope()); logger.debug(" Messages = " + context.getMessageContext()); } context.viewRendering(view); renderActionList.execute(context); try { view.render(); } catch (IOException e) { throw new ViewRenderingException(getOwner().getId(), getId(), view, e); } clearFlash(context); context.getExternalContext().recordResponseComplete(); context.viewRendered(view); }
assertTrue("A JsfView was expected", restoredView instanceof JsfView); assertEquals("View name did not match", VIEW_ID, ((JsfView) restoredView).getViewRoot().getViewId()); assertFalse("An unexpected event was signaled,", restoredView.hasFlowEvent()); assertSame("The UIInput binding was not restored properly", input, testBean.getInput()); assertSame("The faceted UIOutput binding was not restored properly", output, testBean.getOutput());
View view = viewFactory.getView(context); context.setCurrentView(view); if (view.userEventQueued()) { boolean stateExited = handleEvent(view, context); if (!stateExited) { if (externalContext.isResponseComplete()) { if (externalContext.isResponseCompleteFlowExecutionRedirect()) { context.getFlashScope().put(View.USER_EVENT_STATE_ATTRIBUTE, view.getUserEventState()); } else { clearFlash(context); } else { if (shouldRedirectInSameState(context)) { context.getFlashScope().put(View.USER_EVENT_STATE_ATTRIBUTE, view.getUserEventState()); externalContext.requestFlowExecutionRedirect(); } else {
public void resume(RequestControlContext context) { restoreVariables(context); View view = viewFactory.getView(context); view.processUserEvent(); if (view.hasFlowEvent()) { Event event = view.getFlowEvent(); if (logger.isDebugEnabled()) { logger.debug("Event '" + event.getId() + "' returned from view " + view); } context.getRequestScope().put("webflow.originatingViewState", this); boolean stateExited = context.handleEvent(event); if (!stateExited && context.getExternalContext().isResponseAllowed()) { if (context.getExternalContext().isAjaxRequest()) { render(context, view); } else { context.getExternalContext().requestFlowExecutionRedirect(); } } } else { if (context.getExternalContext().isResponseAllowed()) { render(context, view); } } }
protected Event doExecute(RequestContext context) throws Exception { if (viewFactory != null) { viewFactory.getView(context).render(); } return new Event(this, "success"); } }
/** * View already exists in view/flash scope and must be restored and the lifecycle executed, no flow event signaled */ public final void testGetView_Restore() { this.lifecycle = new NoExecutionLifecycle(this.jsfMock.lifecycle()); this.factory = new JsfViewFactory(this.parser.parseExpression(VIEW_ID, new FluentParserContext().template().evaluate(RequestContext.class).expectResult(String.class)), this.lifecycle); MockUIViewRoot existingRoot = new MockUIViewRoot(); existingRoot.setViewId(VIEW_ID); UIInput input = new UIInput(); input.setId("invalidInput"); input.setValid(false); existingRoot.getChildren().add(input); ((MockViewHandler) this.viewHandler).setRestoreView(existingRoot); this.context.inViewState(); EasyMock.expectLastCall().andReturn(true); EasyMock.replay(this.context); View restoredView = this.factory.getView(this.context); assertNotNull("A View was not restored", restoredView); assertTrue("A JsfView was expected", restoredView instanceof JsfView); assertEquals("View name did not match", VIEW_ID, ((JsfView) restoredView).getViewRoot().getViewId()); assertFalse("An unexpected event was signaled,", restoredView.hasFlowEvent()); assertTrue("The input component's valid flag was not reset", input.isValid()); assertTrue("The PostRestoreViewEvent was not seen", existingRoot.isPostRestoreStateEventSeen()); }
protected Event doExecute(RequestContext context) throws Exception { if (viewFactory != null) { viewFactory.getView(context).render(); } return new Event(this, "success"); } }
/** * Third party sets the view root before RESTORE_VIEW */ public final void testGetView_ExternalViewRoot() { this.lifecycle = new NoExecutionLifecycle(this.jsfMock.lifecycle()); this.factory = new JsfViewFactory(this.parser.parseExpression(VIEW_ID, new FluentParserContext().template().evaluate(RequestContext.class).expectResult(String.class)), this.lifecycle); MockUIViewRoot newRoot = new MockUIViewRoot(); newRoot.setViewId(VIEW_ID); this.jsfMock.facesContext().setViewRoot(newRoot); this.jsfMock.facesContext().renderResponse(); EasyMock.replay(this.context); View newView = this.factory.getView(this.context); assertNotNull("A View was not created", newView); assertTrue("A JsfView was expected", newView instanceof JsfView); assertEquals("View name did not match", VIEW_ID, ((JsfView) newView).getViewRoot().getViewId()); assertSame("View root was not the third party instance", newRoot, ((JsfView) newView).getViewRoot()); assertFalse("An unexpected event was signaled,", newView.hasFlowEvent()); assertTrue("The PostRestoreViewEvent was not seen", newRoot.isPostRestoreStateEventSeen()); }
private void render(RequestControlContext context, View view) throws ViewRenderingException { if (logger.isDebugEnabled()) { logger.debug("Rendering + " + view); logger.debug(" Flash scope = " + context.getFlashScope()); logger.debug(" Messages = " + context.getMessageContext()); } context.viewRendering(view); renderActionList.execute(context); try { view.render(); } catch (IOException e) { throw new ViewRenderingException(getOwner().getId(), getId(), view, e); } clearFlash(context); context.getExternalContext().recordResponseComplete(); context.viewRendered(view); }