org.springframework.webflow.engine.Flow.setApplicationContext()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(12.2k)|赞(0)|评价(0)|浏览(100)

本文整理了Java中org.springframework.webflow.engine.Flow.setApplicationContext()方法的一些代码示例,展示了Flow.setApplicationContext()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Flow.setApplicationContext()方法的具体详情如下:
包路径:org.springframework.webflow.engine.Flow
类名称:Flow
方法名:setApplicationContext

Flow.setApplicationContext介绍

[英]Sets a reference to the application context hosting application objects needed by this flow.
[中]设置对此流所需的承载应用程序对象的应用程序上下文的引用。

代码示例

代码示例来源:origin: org.springframework.webflow/spring-webflow

protected Flow createFlow() {
  String flowId = getContext().getFlowId();
  AttributeMap<Object> flowAttributes = parseFlowMetaAttributes(flowModel);
  flowAttributes = getContext().getFlowAttributes().union(flowAttributes);
  if (IS_SPRING_FACES_PRESENT) {
    flowAttributes.asMap().put(VALIDATOR_FLOW_ATTR, getLocalContext().getValidator());
    flowAttributes.asMap().put(VALIDATION_HINT_RESOLVER_FLOW_ATTR, getLocalContext().getValidationHintResolver());
  }
  Flow flow = getLocalContext().getFlowArtifactFactory().createFlow(flowId, flowAttributes);
  flow.setApplicationContext(getLocalContext().getApplicationContext());
  return flow;
}

代码示例来源:origin: spring-projects/spring-webflow

protected Flow createFlow() {
  String flowId = getContext().getFlowId();
  AttributeMap<Object> flowAttributes = parseFlowMetaAttributes(flowModel);
  flowAttributes = getContext().getFlowAttributes().union(flowAttributes);
  if (IS_SPRING_FACES_PRESENT) {
    flowAttributes.asMap().put(VALIDATOR_FLOW_ATTR, getLocalContext().getValidator());
    flowAttributes.asMap().put(VALIDATION_HINT_RESOLVER_FLOW_ATTR, getLocalContext().getValidationHintResolver());
  }
  Flow flow = getLocalContext().getFlowArtifactFactory().createFlow(flowId, flowAttributes);
  flow.setApplicationContext(getLocalContext().getApplicationContext());
  return flow;
}

代码示例来源:origin: org.springframework.webflow/org.springframework.webflow

protected Flow createFlow() {
  String flowId = getContext().getFlowId();
  AttributeMap flowAttributes = parseFlowMetaAttributes(flowModel);
  flowAttributes = getContext().getFlowAttributes().union(flowAttributes);
  Flow flow = getLocalContext().getFlowArtifactFactory().createFlow(flowId, flowAttributes);
  flow.setApplicationContext(getLocalContext().getApplicationContext());
  return flow;
}

代码示例来源:origin: spring-projects/spring-webflow

public void testValidateWithErrorsForBeanValidatorOverridden() {
  StaticApplicationContext applicationContext = new StaticApplicationContext();
  applicationContext.registerSingleton("modelValidator", StubModelErrorsOverridden.class);
  ((Flow) requestContext.getActiveFlow()).setApplicationContext(applicationContext);
  ValidationHelper helper = new ValidationHelper(new Object(), requestContext, eventId, modelName, null,
      this.codesResolver, null);
  helper.validate();
  MessageContext messages = requestContext.getMessageContext();
  assertEquals(1, messages.getAllMessages().length);
  assertEquals(1, messages.getMessagesBySource("validationcontext-external").length);
}

代码示例来源:origin: spring-projects/spring-webflow

public void testValidateWithValidationContextForBeanValidator() {
  StaticApplicationContext applicationContext = new StaticApplicationContext();
  applicationContext.registerSingleton("modelValidator", StubModelValidationContext.class);
  ((Flow) requestContext.getActiveFlow()).setApplicationContext(applicationContext);
  ValidationHelper helper = new ValidationHelper(new Object(), requestContext, eventId, modelName, null,
      this.codesResolver, null);
  helper.validate();
  MessageContext messages = requestContext.getMessageContext();
  assertEquals(1, messages.getAllMessages().length);
  assertEquals(1, messages.getMessagesBySource("validationcontext-external").length);
}

代码示例来源:origin: spring-projects/spring-webflow

public void testValidateWithMessageContextForBeanValidator() {
  StaticApplicationContext applicationContext = new StaticApplicationContext();
  applicationContext.registerSingleton("modelValidator", StubModelMessageContext.class);
  ((Flow) requestContext.getActiveFlow()).setApplicationContext(applicationContext);
  ValidationHelper helper = new ValidationHelper(new Object(), requestContext, eventId, modelName, null,
      this.codesResolver, null);
  helper.validate();
  MessageContext messages = requestContext.getMessageContext();
  assertEquals(1, messages.getAllMessages().length);
  assertEquals(1, messages.getMessagesBySource("messagecontext-external").length);
}

代码示例来源:origin: spring-projects/spring-webflow

public void testValidateWithErrorsForBeanValidator() {
  StaticApplicationContext applicationContext = new StaticApplicationContext();
  applicationContext.registerSingleton("modelValidator", StubModelErrors.class);
  ((Flow) requestContext.getActiveFlow()).setApplicationContext(applicationContext);
  ValidationHelper helper = new ValidationHelper(new Object(), requestContext, eventId, modelName, null,
      this.codesResolver, null);
  helper.validate();
  MessageContext messages = requestContext.getMessageContext();
  assertEquals(1, messages.getAllMessages().length);
  assertEquals(1, messages.getMessagesBySource("errors-external").length);
}

代码示例来源:origin: spring-projects/spring-webflow

public void testDestroy() {
  GenericApplicationContext context = new GenericApplicationContext();
  context.refresh();
  flow.setApplicationContext(context);
  assertTrue(context.isActive());
  flow.destroy();
  assertFalse(context.isActive());
}

代码示例来源:origin: spring-projects/spring-webflow

public void testFlowResourceResolve() {
  ApplicationContext applicationContext = new StaticWebApplicationContext();
  ((Flow) this.requestContext.getActiveFlow()).setApplicationContext(applicationContext);
  Object actual = this.resolver.getValue(this.elContext, null, "resourceBundle");
  assertTrue(this.elContext.isPropertyResolved());
  assertNotNull(actual);
  assertSame(applicationContext, actual);
}

代码示例来源:origin: spring-projects/spring-webflow

public void testResolveSpringBean() {
  MockRequestContext context = new MockRequestContext();
  StaticApplicationContext ac = new StaticApplicationContext();
  ac.getBeanFactory().registerSingleton("testBean", new TestBean());
  context.getRootFlow().setApplicationContext(ac);
  Expression exp = parser.parseExpression("testBean", new FluentParserContext().evaluate(RequestContext.class));
  assertSame(ac.getBean("testBean"), exp.getValue(context));
}

代码示例来源:origin: spring-projects/spring-webflow

public void testResolveAction() {
  MockRequestContext context = new MockRequestContext();
  StaticApplicationContext ac = new StaticApplicationContext();
  ac.getBeanFactory().registerSingleton("action", new TestAction());
  context.getRootFlow().setApplicationContext(ac);
  Expression exp = parser.parseExpression("action", new FluentParserContext().evaluate(RequestContext.class));
  assertSame(ac.getBean("action"), exp.getValue(context));
}

代码示例来源:origin: spring-projects/spring-webflow

public void testBeanResolveWithRequestContext() {
  StaticWebApplicationContext applicationContext = new StaticWebApplicationContext();
  ((Flow) this.requestContext.getActiveFlow()).setApplicationContext(applicationContext);
  applicationContext.registerSingleton("test", Bean.class);
  Object actual = this.resolver.getValue(this.elContext, null, "test");
  assertTrue(this.elContext.isPropertyResolved());
  assertNotNull(actual);
  assertTrue(actual instanceof Bean);
}

代码示例来源:origin: spring-projects/spring-webflow

public void testGetValue_BaseVariable() {
  MockRequestContext requestContext = new MockRequestContext();
  ((Flow) requestContext.getActiveFlow()).setApplicationContext(new StaticWebApplicationContext());
  RequestContextHolder.setRequestContext(requestContext);
  assertTrue(getBaseVariable() + " should resolve to an instance of MessageSource", context.getELResolver()
      .getValue(context, null, getBaseVariable()) instanceof MessageSource);
}

代码示例来源:origin: spring-projects/spring-webflow

public void testResolveMultiAction() {
  MockRequestContext context = new MockRequestContext();
  StaticApplicationContext ac = new StaticApplicationContext();
  ac.getBeanFactory().registerSingleton("multiAction", new FormAction());
  context.getRootFlow().setApplicationContext(ac);
  Expression exp = parser.parseExpression("multiAction.setupForm",
      new FluentParserContext().evaluate(RequestContext.class));
  AnnotatedAction action = (AnnotatedAction) exp.getValue(context);
  assertSame(ac.getBean("multiAction"), action.getTargetAction());
  assertEquals("setupForm", action.getMethod());
}

代码示例来源:origin: spring-projects/spring-webflow

public void testStateAndFallbackLegacyValidatorInvoked() {
  LegacyModelValidator validator = new LegacyModelValidator();
  StaticApplicationContext applicationContext = new StaticApplicationContext();
  applicationContext.getBeanFactory().registerSingleton("modelValidator", validator);
  requestContext.getRootFlow().setApplicationContext(applicationContext);
  Model model = new Model();
  ValidationHelper helper = new ValidationHelper(model, requestContext, eventId, modelName, null,
      this.codesResolver, null);
  ViewState state1 = new ViewState(requestContext.getRootFlow(), "state1", new StubViewFactory());
  requestContext.setCurrentState(state1);
  helper.validate();
  assertTrue(validator.state1Invoked);
  assertTrue(validator.fallbackInvoked);
}

代码示例来源:origin: spring-projects/spring-webflow

public void testStateAndFallbackErrorsValidatorInvoked() {
  ErrorsModelValidator validator = new ErrorsModelValidator();
  StaticApplicationContext applicationContext = new StaticApplicationContext();
  applicationContext.getBeanFactory().registerSingleton("modelValidator", validator);
  requestContext.getRootFlow().setApplicationContext(applicationContext);
  Model model = new Model();
  ValidationHelper helper = new ValidationHelper(model, requestContext, eventId, modelName, null,
      this.codesResolver, null);
  ViewState state1 = new ViewState(requestContext.getRootFlow(), "state1", new StubViewFactory());
  requestContext.setCurrentState(state1);
  helper.validate();
  assertTrue(validator.state1Invoked);
  assertTrue(validator.fallbackInvoked);
}

代码示例来源:origin: spring-projects/spring-webflow

public void testStateAndFallbackValidatorInvokedForSubclass() {
  ModelValidator validator = new ModelValidator();
  StaticApplicationContext applicationContext = new StaticApplicationContext();
  applicationContext.getBeanFactory().registerSingleton("modelValidator", validator);
  requestContext.getRootFlow().setApplicationContext(applicationContext);
  ExtendedModel model = new ExtendedModel();
  ValidationHelper helper = new ValidationHelper(model, requestContext, eventId, modelName, null,
      this.codesResolver, null);
  ViewState state1 = new ViewState(requestContext.getRootFlow(), "state1", new StubViewFactory());
  requestContext.setCurrentState(state1);
  helper.validate();
  assertTrue(validator.state1Invoked);
  assertTrue(validator.fallbackInvoked);
}

代码示例来源:origin: spring-projects/spring-webflow

public void testFallbackErrorsValidatorInvokedForSubclass() {
  ErrorsModelValidator validator = new ErrorsModelValidator();
  StaticApplicationContext applicationContext = new StaticApplicationContext();
  applicationContext.getBeanFactory().registerSingleton("modelValidator", validator);
  requestContext.getRootFlow().setApplicationContext(applicationContext);
  Model model = new Model();
  ValidationHelper helper = new ValidationHelper(model, requestContext, eventId, modelName, null,
      this.codesResolver, null);
  ViewState state1 = new ViewState(requestContext.getRootFlow(), "state2", new StubViewFactory());
  requestContext.setCurrentState(state1);
  helper.validate();
  assertFalse(validator.state1Invoked);
  assertTrue(validator.fallbackInvoked);
}

代码示例来源:origin: spring-projects/spring-webflow

public void testResourceBundle() throws Exception {
  Flow flow = (Flow) requestContext.getActiveFlow();
  flow.setApplicationContext(new StaticApplicationContext());
  assertTrue(accessor.canRead(null, null, "resourceBundle"));
  assertNotNull(accessor.read(null, null, "resourceBundle").getValue());
  assertEquals(requestContext.getActiveFlow().getApplicationContext(), accessor
      .read(null, null, "resourceBundle").getValue());
}

代码示例来源:origin: spring-projects/spring-webflow

public void testResolveMessage() {
    MockRequestContext context = new MockRequestContext();
    StaticApplicationContext ac = new StaticApplicationContext();
    ac.getStaticMessageSource().addMessage("foo", Locale.FRANCE, "bar");
    ac.refresh();
    context.getRootFlow().setApplicationContext(ac);
    context.getMockExternalContext().setLocale(Locale.FRANCE);
    Expression exp = parser.parseExpression("resourceBundle.foo",
        new FluentParserContext().evaluate(RequestContext.class));
    assertEquals("bar", exp.getValue(context));
  }
}

相关文章