【问题标题】:Spring Webflow - How to Get List of FLOW IDsSpring Webflow - 如何获取 FLOW ID 列表
【发布时间】:2014-07-13 04:11:48
【问题描述】:

获取 Spring Webflow 生成的 FLOW ID 的完整列表的最佳方法是什么?

这是我的配置:

<webflow:flow-registry id="flowRegistry" 
           flow-builder-services="flowBuilderServices" 
           base-path="/WEB-INF/pageFlows">
     <webflow:flow-location-pattern value="/**/*-flow.xml"/>    
</webflow:flow-registry>

[更新 1] 我应该澄清我想在 Java 代码中执行此操作,而不是通过检查我的配置。

[更新 2] 答案:requestContext.getActiveFlow().getApplicationContext()

【问题讨论】:

  • 检查我更新的答案。
  • 泰。这有助于通过 MVC 访问。你能告诉我如何或是否有一种方法可以使用 org.springframework.webflow.execution.RequestContext 从 org.springframework.webflow.action.MultiAction 中访问 ApplicationContext?
  • requestContext.getActiveFlow().getApplicationContext() 将完成这项工作。

标签: spring-webflow


【解决方案1】:

流ID列表可以通过流注册中定义的方式来识别。默认情况下,除非定义了注册表基本路径,否则将为流分配等于其文件名减去文件扩展名的注册表标识符。

让我用例子来解释一下:

场景 1: 未指定流位置和基本路径:

    <webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
        <webflow:flow-location path="/WEB-INF/pageFlows/example.xml" />  
    </webflow:flow-registry>

流 ID:示例

场景 2: 未指定流位置模式和基本路径:

    <webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
        <webflow:flow-location-pattern value="/WEB-INF/pageFlows/**/*-flow.xml"/>
    </webflow:flow-registry>

如果您有 /WEB-INF/pageFlows/example1-flow.xml、/WEB-INF/pageFlows/example2-flow.xml 等流,则流 ID 分别为:example1-flow、example2-flow。

场景 3: 指定了您自己的 id:

    <webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
        <webflow:flow-location path="/WEB-INF/pageFlows/example.xml" id="myExampleId" />  
    </webflow:flow-registry>

流 ID:myExampleId

场景 4: 指定了基本路径:

    <webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices" base-path="/WEB-INF">
        <webflow:flow-location path="/pageFlows/example.xml" />
    </webflow:flow-registry>

现在将为流分配注册表标识符,该标识符等于其基本路径和文件名之间的路径段。 流id:pageFlows

场景 5: 指定了 flow-location-pattern 和 base-path:

    <webflow:flow-registry id="flowRegistry" base-path="/WEB-INF">
        <webflow:flow-location-pattern value="/**/*-flow.xml" />
    </webflow:flow-registry>

现在将为流分配注册表标识符,该标识符等于其基本路径和文件名之间的路径段。 因此,如果您的流位于 WEB-INF 内的 /pageFlows1/example1、/pageFlows2/example2 目录中,则流 ID 分别为:pageFlows1、pageFlows2。

编辑:

以编程方式获取流 ID:

假设您在 webflow-config xml 文件中的流控制器和 flowexecutor 定义如下:

    <bean name="flowController" class="org.springframework.webflow.executor.mvc.FlowController">
        <property name="flowExecutor" ref="flowExecutor" />
    </bean>
    //flowRegistry is alredy mentioned in your question
    <flow:executor id="flowExecutor" registry-ref="flowRegistry">
        <flow:repository type="continuation" max-conversations="1" max-continuations="30" />
    </flow:executor>

您可以检索注册如下的流定义ID: (我从一个扩展 AbstractController 的控制器调用它,这就是为什么你会看到 getServletContext() 方法)

    ApplicationContext context = 
        (ApplicationContext)getServletContext().getAttribute(
            DispatcherServlet.SERVLET_CONTEXT_PREFIX + "yourWebContextName");       
    FlowController controller = (FlowController)context.getBean("flowController");
    FlowExecutorImpl flowExecutorImpl = (FlowExecutorImpl)controller.getFlowExecutor();
    FlowDefinitionRegistryImpl flowDefinitionRegistryImpl = (FlowDefinitionRegistryImpl)flowExecutorImpl.getDefinitionLocator();
    //Assuming you have log configured
    log.info("Registered Flow Ids are:"+flowDefinitionRegistryImpl.getFlowDefinitionIds());

FlowController 可以访问 FlowExecutor(webflow 的初始入口点)。 FlowExecutor 可以访问 flowDefinitionRegistry,所有流在被提供给请求之前都会在其中注册。

希望这会有所帮助。

【讨论】:

  • 所以总结一下。如果提供了明确的 ID,则按原样使用。如果不是默认情况下,除非定义了注册表基本路径,否则将为流分配等于其文件名减去文件扩展名的注册表标识符。如果提供了基本路径,现在将为流分配注册表标识符,该标识符等于它们的基本路径和文件名之间的路径段。
猜你喜欢
  • 1970-01-01
  • 2018-09-22
  • 1970-01-01
  • 1970-01-01
  • 2012-07-28
  • 1970-01-01
  • 2021-09-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多