logger.debug("Executing " + this); context.setCurrentTransition(this); if (targetStateResolver != null) { State targetState = targetStateResolver.resolveTargetState(this, sourceState, context); if (context.getFlowExecutionContext().isActive()) { logger.debug("Completed transition execution. As a result, the new state is '" + context.getCurrentState().getId() + "' in flow '" + context.getActiveFlow().getId() + "'"); } else { logger.debug("Completed transition execution. As a result, the flow execution has ended");
/** * Inform this state definition that an event was signaled in it. The signaled event is the last event available in * given request context ({@link RequestContext#getCurrentEvent()}). * @param context the flow execution control context * @throws NoMatchingTransitionException when a matching transition cannot be found */ public boolean handleEvent(RequestControlContext context) throws NoMatchingTransitionException { return context.execute(getRequiredTransition(context)); }
eventIds[executionCount] = event.getId(); try { context.handleEvent(event); return; } catch (NoMatchingActionResultTransitionException e) { throw new NoMatchingTransitionException(getFlow().getId(), getId(), context.getCurrentEvent(), "No transition was matched on the event(s) signaled by the [" + executionCount + "] action(s) that executed in this action state '" + getId() + "' of flow '"
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); }
protected void doEnter(RequestControlContext context) throws FlowExecutionException { context.assignFlowExecutionKey(); ExternalContext externalContext = context.getExternalContext(); if (externalContext.isResponseComplete()) { if (!externalContext.isResponseCompleteFlowExecutionRedirect()) { clearFlash(context); } } else { if (shouldRedirect(context)) { context.getExternalContext().requestFlowExecutionRedirect(); if (popup) { context.getExternalContext().requestRedirectInPopup(); } } else { View view = viewFactory.getView(context); context.setCurrentView(view); render(context, view); } } }
/** * Specialization of State's <code>doEnter</code> template method that executes behavior specific to this state type * in polymorphic fashion. * <p> * This implementation pops the top (active) flow session off the execution stack, ending it, and resumes control in * the parent flow (if necessary). If the ended session is the root flow, a final response is rendered. * @param context the control context for the currently executing flow, used by this state to manipulate the flow * execution * @throws FlowExecutionException if an exception occurs in this state */ protected void doEnter(final RequestControlContext context) throws FlowExecutionException { FlowSession activeSession = context.getFlowExecutionContext().getActiveSession(); if (activeSession.isRoot()) { // entire flow execution is ending; issue the final response if (finalResponseAction != null && !context.getExternalContext().isResponseComplete()) { ActionExecutor.execute(finalResponseAction, context); context.getExternalContext().recordResponseComplete(); } context.endActiveFlowSession(getId(), createSessionOutput(context)); } else { // there is a parent flow that will resume (this flow is a subflow) LocalAttributeMap<Object> sessionOutput = createSessionOutput(context); context.endActiveFlowSession(getId(), sessionOutput); } }
protected void doEnter(RequestControlContext context) throws FlowExecutionException { context.assignFlowExecutionKey(); context.updateCurrentFlowExecutionSnapshot(); context.removeCurrentFlowExecutionSnapshot(); context.removeAllFlowExecutionSnapshots(); } };
context.setLastTransition(this); if (context.getFlowExecutionContext().isActive()) { logger.debug("Completed execution of " + this + ", as a result the new state is '" + context.getCurrentState().getId() + "' in flow '" + context.getActiveFlow().getId() + "'"); } else { logger.debug("Completed execution of " + this + ", as a result the flow execution has ended");
private TransitionableState getCurrentTransitionableState(RequestControlContext context) { State currentState = (State) context.getCurrentState(); if (!(currentState instanceof TransitionableState)) { throw new IllegalStateException("You can only signal events in transitionable states, and state " + context.getCurrentState() + " is not transitionable - programmer error"); } return (TransitionableState) currentState; }
public void resume(RequestControlContext context) { restoreVariables(context); View view = viewFactory.getView(context); context.setCurrentView(view); if (view.userEventQueued()) { boolean stateExited = handleEvent(view, context); if (!stateExited) { ExternalContext externalContext = context.getExternalContext(); 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 {
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; } }
public void handle(FlowExecutionException exception, RequestControlContext requestControlContext) { requestControlContext.getMessageContext().addMessage( new MessageBuilder() .error() .source(null) .defaultText( findBusinessException(exception).getMessage()) .build()); Object testState = requestControlContext.getCurrentState(); if (testState instanceof ViewState) { ViewState viewState = (ViewState) testState; try { viewState.getViewFactory().getView(requestControlContext) .render(); } catch (IOException e) { e.printStackTrace(); // Properly handle rendering errors here } } }
/** * Specialization of State's <code>doEnter</code> template method that executes behaviour specific to this state * type in polymorphic fashion. * <p> * This implementation pops the top (active) flow session off the execution stack, ending it, and resumes control in * the parent flow (if neccessary). If the ended session is the root flow, a {@link ViewSelection} is returned. * @param context the control context for the currently executing flow, used by this state to manipulate the flow * execution * @return a view selection signaling that control should be returned to the client and a view rendered * @throws FlowExecutionException if an exception occurs in this state */ protected ViewSelection doEnter(RequestControlContext context) throws FlowExecutionException { FlowSession activeSession = context.getFlowExecutionContext().getActiveSession(); if (activeSession.isRoot()) { // entire flow execution is ending, return ending view if applicable ViewSelection selectedView = viewSelector.makeEntrySelection(context); context.endActiveFlowSession(createSessionOutput(context)); return selectedView; } else { // there is a parent flow that will resume (this flow is a subflow) LocalAttributeMap sessionOutput = createSessionOutput(context); context.endActiveFlowSession(sessionOutput); return context.signalEvent(new Event(this, getId(), sessionOutput)); } }
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 void doEnter(RequestControlContext context) throws FlowExecutionException { context.assignFlowExecutionKey(); if (context.getExternalContext().isResponseAllowed()) { if (shouldRedirect(context)) { context.getExternalContext().requestFlowExecutionRedirect(); if (popup) { context.getExternalContext().requestRedirectInPopup(); } } else { View view = viewFactory.getView(context); render(context, view); } } }
/** * Called on completion of the subflow to handle the subflow result event as determined by the end state reached by * the subflow. */ public boolean handleEvent(RequestControlContext context) { if (subflowAttributeMapper != null) { AttributeMap<Object> subflowOutput = context.getCurrentEvent().getAttributes(); if (logger.isDebugEnabled()) { logger.debug("Mapping subflow output " + subflowOutput); } subflowAttributeMapper.mapSubflowOutput(subflowOutput, context); } return super.handleEvent(context); }
void start(Flow flow, MutableAttributeMap<?> input, RequestControlContext context) { listeners.fireSessionCreating(context, flow); FlowSessionImpl session = activateSession(flow); if (session.isRoot()) { status = FlowExecutionStatus.ACTIVE; } if (input == null) { input = new LocalAttributeMap<>(); } if (hasEmbeddedModeAttribute(input)) { session.setEmbeddedMode(); } StateManageableMessageContext messageContext = (StateManageableMessageContext) context.getMessageContext(); messageContext.setMessageSource(flow.getApplicationContext()); listeners.fireSessionStarting(context, session, input); flow.start(context, input); listeners.fireSessionStarted(context, session); }
public ViewSelection signalEvent(String eventId, ExternalContext externalContext) throws FlowExecutionException { assertActive(); if (logger.isDebugEnabled()) { logger.debug("Resuming execution on user event '" + eventId + "'"); } RequestControlContext context = createControlContext(externalContext); context.getFlashScope().clear(); getListeners().fireRequestSubmitted(context); try { try { resume(context); Event event = new Event(externalContext, eventId, externalContext.getRequestParameterMap() .asAttributeMap()); ViewSelection selectedView = context.signalEvent(event); return pause(context, selectedView); } catch (FlowExecutionException e) { return pause(context, handleException(e, context)); } catch (Exception e) { return pause(context, handleException(wrapException(e), context)); } } finally { getListeners().fireRequestProcessed(context); } }
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); } context.getFlashScope().clear(); context.getMessageContext().clearMessages(); context.getExternalContext().recordResponseComplete(); context.viewRendered(view); }
/** * Specialization of State's <code>doEnter</code> template method that executes behavior specific to this state * type in polymorphic fashion. * <p> * This implementation pops the top (active) flow session off the execution stack, ending it, and resumes control in * the parent flow (if necessary). If the ended session is the root flow, a final response is rendered. * @param context the control context for the currently executing flow, used by this state to manipulate the flow * execution * @throws FlowExecutionException if an exception occurs in this state */ protected void doEnter(final RequestControlContext context) throws FlowExecutionException { FlowSession activeSession = context.getFlowExecutionContext().getActiveSession(); if (activeSession.isRoot()) { // entire flow execution is ending; issue the final response if (finalResponseAction != null && context.getExternalContext().isResponseAllowed()) { ActionExecutor.execute(finalResponseAction, context); context.getExternalContext().recordResponseComplete(); } context.endActiveFlowSession(getId(), createSessionOutput(context)); } else { // there is a parent flow that will resume (this flow is a subflow) LocalAttributeMap sessionOutput = createSessionOutput(context); context.endActiveFlowSession(getId(), sessionOutput); } }