/** * Factory method that creates a new view state, a state where a user is allowed to participate in the flow. This * method is an atomic operation that returns a fully initialized state. It encapsulates the selection of the view * state implementation as well as the state assembly. * @param id the identifier to assign to the state, must be unique to its owning flow (required) * @param flow the flow that will own (contain) this state (required) * @param entryActions any state entry actions; may be null * @param viewFactory the state view factory strategy * @param redirect whether to send a flow execution redirect before rendering * @param popup whether to display the view in a popup window * @param renderActions any 'render actions' to execute on entry and refresh; may be null * @param transitions any transitions (paths) out of this state; may be null * @param exceptionHandlers any exception handlers; may be null * @param exitActions any state exit actions; may be null * @param attributes attributes to assign to the State, which may also be used to affect state construction; may be * null * @return the fully initialized view state instance */ public State createViewState(String id, Flow flow, ViewVariable[] variables, Action[] entryActions, ViewFactory viewFactory, Boolean redirect, boolean popup, Action[] renderActions, Transition[] transitions, FlowExecutionExceptionHandler[] exceptionHandlers, Action[] exitActions, AttributeMap<?> attributes) { ViewState viewState = new ViewState(flow, id, viewFactory); viewState.addVariables(variables); viewState.setRedirect(redirect); viewState.setPopup(popup); viewState.getRenderActionList().addAll(renderActions); configureCommonProperties(viewState, entryActions, transitions, exceptionHandlers, exitActions, attributes); return viewState; }
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); }
/** * Gets state binder configuration. * * @param state the state * @return the state binder configuration */ public BinderConfiguration getViewStateBinderConfiguration(final ViewState state) { val field = ReflectionUtils.findField(state.getViewFactory().getClass(), "binderConfiguration"); ReflectionUtils.makeAccessible(field); return (BinderConfiguration) ReflectionUtils.getField(field, state.getViewFactory()); }
public void testRedirectInSameStateOverridesAlwaysRedirectOnPause() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); Transition t = new Transition(on("submit"), null); state.getTransitionSet().add(t); MockRequestControlContext context = new MockRequestControlContext(flow); state.enter(context); context = new MockRequestControlContext(context.getFlowExecutionContext()); context.setAlwaysRedirectOnPause(false); context.setRedirectInSameState(true); context.getFlowScope().remove("renderCalled"); context.putRequestParameter("_eventId", "submit"); state.resume(context); assertTrue(context.getMockExternalContext().getFlowExecutionRedirectRequested()); }
/** * Creates a new mock flow session that sets a flow with id "mockFlow" as the 'active flow' in state "mockState". * This session marks itself active. */ public MockFlowSession() { setDefinition(new Flow("mockFlow")); State state = new ViewState(definition, "mockState"); setStatus(FlowSessionStatus.ACTIVE); setState(state); }
/** * Add view state. * * @param flow the flow * @param id the id * @param expression the expression * @return the view state */ protected ViewState createViewState(final Flow flow, final String id, final Expression expression) { try { final ViewFactory viewFactory = this.flowBuilderServices.getViewFactoryCreator().createViewFactory( expression, this.flowBuilderServices.getExpressionParser(), this.flowBuilderServices.getConversionService(), null, this.flowBuilderServices.getValidator(), this.flowBuilderServices.getValidationHintResolver()); final ViewState viewState = new ViewState(flow, id, viewFactory); logger.debug("Added view state {}", viewState.getId()); return viewState; } catch (final Exception e) { logger.error(e.getMessage(), e); } return null; }
public void testCreateVariable() { ViewVariable var = new ViewVariable("foo", new VariableValueFactory() { public Object createInitialValue(RequestContext context) { return "bar"; } public void restoreReferences(Object value, RequestContext context) { } }); Flow flow = new Flow("flow"); ViewState view = new ViewState(flow, "view", new StubViewFactory()); MockRequestControlContext context = new MockRequestControlContext(flow); view.enter(context); var.create(context); assertEquals("bar", context.getViewScope().get("foo")); }
protected void setUp() throws Exception { flow = new Flow("myFlow"); ViewState s1 = new ViewState(flow, "state", new StubViewFactory()); s1.getTransitionSet().add(new Transition(new DefaultTargetStateResolver("state2"))); new ViewState(flow, "state2", new StubViewFactory()); conversationManager = new StubConversationManager(); FlowDefinitionLocator locator = flowId -> flow; SerializedFlowExecutionSnapshotFactory snapshotFactory = new SerializedFlowExecutionSnapshotFactory( executionFactory, locator); repository = new DefaultFlowExecutionRepository(conversationManager, snapshotFactory); executionFactory.setExecutionKeyFactory(repository); }
/** * Factory method that creates a new view state, a state where a user is allowed to participate in the flow. This * method is an atomic operation that returns a fully initialized state. It encapsulates the selection of the view * state implementation as well as the state assembly. * @param id the identifier to assign to the state, must be unique to its owning flow (required) * @param flow the flow that will own (contain) this state (required) * @param entryActions any state entry actions; may be null * @param viewSelector the state view selector strategy; may be null * @param renderActions any 'render actions' to execute on entry and refresh; may be null * @param transitions any transitions (paths) out of this state; may be null * @param exceptionHandlers any exception handlers; may be null * @param exitActions any state exit actions; may be null * @param attributes attributes to assign to the State, which may also be used to affect state construction; may be * null * @return the fully initialized view state instance * @throws FlowArtifactLookupException an exception occured creating the state */ public State createViewState(String id, Flow flow, Action[] entryActions, ViewSelector viewSelector, Action[] renderActions, Transition[] transitions, FlowExecutionExceptionHandler[] exceptionHandlers, Action[] exitActions, AttributeMap attributes) throws FlowArtifactLookupException { ViewState viewState = new ViewState(flow, id); if (viewSelector != null) { viewState.setViewSelector(viewSelector); } viewState.getRenderActionList().addAll(renderActions); configureCommonProperties(viewState, entryActions, transitions, exceptionHandlers, exitActions, attributes); return viewState; }
public void testEnterViewStateRedirectInPopup() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); state.setRedirect(true); state.setPopup(true); MockRequestControlContext context = new MockRequestControlContext(flow); context.getFlashScope().put("foo", "bar"); state.enter(context); assertFalse("Render called", context.getFlowScope().contains("renderCalled")); assertTrue(context.getMockExternalContext().getFlowExecutionRedirectRequested()); assertTrue(context.getMockExternalContext().getRedirectInPopup()); assertTrue(context.getFlashScope().contains("foo")); }
public void testEnterViewStateWithLocalRedirect() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); state.setRedirect(true); MockRequestControlContext context = new MockRequestControlContext(flow); context.getFlashScope().put("foo", "bar"); state.enter(context); assertFalse("Render called", context.getFlowScope().contains("renderCalled")); assertTrue(context.getMockExternalContext().getFlowExecutionRedirectRequested()); assertTrue(context.getFlashScope().contains("foo")); }
public void testViewStateRedirectOverridesEmbeddedMode() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); state.setRedirect(false); Transition t = new Transition(on("submit"), null); state.getTransitionSet().add(t); MockRequestControlContext context = new MockRequestControlContext(flow); state.enter(context); context.getMockExternalContext().setAjaxRequest(true); context.setEmbeddedMode(); context.setAlwaysRedirectOnPause(true); context.setRedirectInSameState(true); assertFalse(context.getMockExternalContext().getFlowExecutionRedirectRequested()); }
stateMap.put("isRedirect", ((ViewState) state).getRedirect()); stateMap.put("renderActions", ((ViewState) state).getRenderActionList()); acts = Arrays.stream(((ViewState) state).getVariables()) .map(value -> value.getName() + " -> " + value.getValueFactory().toString()) .collect(Collectors.toList()); val field = ReflectionUtils.findField(((ViewState) state).getViewFactory().getClass(), "viewId"); if (field != null) { ReflectionUtils.makeAccessible(field); val exp = (Expression) ReflectionUtils.getField(field, ((ViewState) state).getViewFactory()); stateMap.put("viewId", StringUtils.defaultIfBlank(exp.getExpressionString(), exp.getValue(null).toString())); } else {
public void testStateEnteringWithSecurity() { SecurityFlowExecutionListener listener = new SecurityFlowExecutionListener(); RequestContext context = new MockRequestContext(); Flow flow = new Flow("flow"); ViewState state = new ViewState(flow, "view", new StubViewFactory()); SecurityRule rule = getSecurityRuleAllAuthorized(); state.getAttributes().put(SecurityRule.SECURITY_ATTRIBUTE_NAME, rule); configureSecurityContext(); listener.stateEntering(context, state); }
public void testEnterViewStateWithVariables() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); state.addVariable(new ViewVariable("foo", new VariableValueFactory() { public Object createInitialValue(RequestContext context) { return "bar"; } public void restoreReferences(Object value, RequestContext context) { } })); MockRequestControlContext context = new MockRequestControlContext(flow); state.enter(context); assertEquals("bar", context.getViewScope().getString("foo")); assertTrue("Render not called", context.getFlowScope().contains("renderCalled")); assertTrue(context.getExternalContext().isResponseComplete()); assertFalse(context.getMockExternalContext().getFlowExecutionRedirectRequested()); }
public void testResumeViewStateForRefresh() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); MockRequestControlContext context = new MockRequestControlContext(flow); state.enter(context); context = new MockRequestControlContext(context.getFlowExecutionContext()); context.getFlashScope().put("foo", "bar"); state.resume(context); assertTrue("Render not called", context.getFlowScope().contains("renderCalled")); assertTrue(context.getExternalContext().isResponseComplete()); assertFalse(context.getMockExternalContext().getFlowExecutionRedirectRequested()); assertFalse(context.getFlashScope().contains("foo")); }
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); }
public void testEmbeddedModeOverridesRedirectInSameState() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); Transition t = new Transition(on("submit"), null); state.getTransitionSet().add(t); MockRequestControlContext context = new MockRequestControlContext(flow); context.getMockExternalContext().setAjaxRequest(true); context.setEmbeddedMode(); context.setAlwaysRedirectOnPause(true); context.setRedirectInSameState(true); state.enter(context); assertFalse(context.getMockExternalContext().getFlowExecutionRedirectRequested()); }
createTransitionForState(sendUsernameInst, CasWebflowConstants.TRANSITION_ID_ERROR, usernameInfo.getId()); createViewState(flow, CasWebflowConstants.VIEW_ID_SENT_FORGOT_USERNAME_ACCT_INFO, CasWebflowConstants.VIEW_ID_SENT_FORGOT_USERNAME_ACCT_INFO); createTransitionForState(sendInst, CasWebflowConstants.TRANSITION_ID_ERROR, accountInfo.getId()); createViewState(flow, CasWebflowConstants.VIEW_ID_SENT_RESET_PASSWORD_ACCT_INFO, CasWebflowConstants.VIEW_ID_SENT_RESET_PASSWORD_ACCT_INFO);
/** * Adds a set of view variables. * @param variables the variables */ public void addVariables(ViewVariable... variables) { for (ViewVariable variable : variables) { addVariable(variable); } }