流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,所有流在被提供给请求之前都会在其中注册。
希望这会有所帮助。