获取 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>
Run Code Online (Sandbox Code Playgroud)
[更新 1] 我应该澄清我想在 Java 代码中执行此操作,而不是通过检查我的配置。
[更新 2] 答案: requestContext.getActiveFlow().getApplicationContext()
流 ID 列表可以通过它们在流注册表中定义的方式来识别。默认情况下,除非定义了注册表基本路径,否则将为流分配等于其文件名减去文件扩展名的注册表标识符。
让我用例子来解释这一点:
场景一: flow-location 和 base-path 未指定:
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
<webflow:flow-location path="/WEB-INF/pageFlows/example.xml" />
</webflow:flow-registry>
Run Code Online (Sandbox Code Playgroud)
流 ID:示例
场景 2: 未指定 flow-location-pattern 和 base-path :
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
<webflow:flow-location-pattern value="/WEB-INF/pageFlows/**/*-flow.xml"/>
</webflow:flow-registry>
Run Code Online (Sandbox Code Playgroud)
如果您有像 /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>
Run Code Online (Sandbox Code Playgroud)
流 ID:myExampleId
场景4: 指定base-path:
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices" base-path="/WEB-INF">
<webflow:flow-location path="/pageFlows/example.xml" />
</webflow:flow-registry>
Run Code Online (Sandbox Code Playgroud)
现在将为流分配等于其基本路径和文件名之间的路径段的注册表标识符。流 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>
Run Code Online (Sandbox Code Playgroud)
现在将为流分配等于其基本路径和文件名之间的路径段的注册表标识符。因此,如果您的流位于 WEB-INF 内的 /pageFlows1/example1、/pageFlows2/example2 目录中,则流 ID 分别为:pageFlows1、pageFlows2。
编辑 :
以编程方式获取流 ID:
假设 webflow-config xml 文件中的流控制器和流执行器定义如下:
<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>
Run Code Online (Sandbox Code Playgroud)
您可以检索如下注册的流定义 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());
Run Code Online (Sandbox Code Playgroud)
FlowController 可以访问 FlowExecutor(webflow 的初始入口点)。FlowExecutor 可以访问 flowDefinitionRegistry,其中所有流在被提供给请求之前都已注册。
希望这可以帮助。
| 归档时间: |
|
| 查看次数: |
3257 次 |
| 最近记录: |