2014-05-23 23 views
1

獲取Spring Webflow生成的FLOW ID完整列表的最佳方式是什麼?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代碼中,沒有通過檢查我的配置。

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

+0

檢查我更新的答案。 Ty。 – Prasad

+0

Ty。這有助於通過MVC訪問。你能告訴我如何或是否有方法使用org.springframework.webflow.execution.RequestContext從org.springframework.webflow.action.MultiAction中訪問ApplicationContext? – daddygames

+0

requestContext.getActiveFlow()。getApplicationContext()將完成這項工作。 – Prasad

回答

3

流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,則flow 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> 

流將被分配註冊表標識符s等於它們的基本路徑和文件名之間的路徑段。 流ID:頁面流

方案5: 流位置的圖案部分和基底部分路徑被指定:

<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,配置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> 

可以檢索流程定義ids註冊如下: (我從一個控制器調用這擴展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()); 

流量控制器訪問FlowExecutor(條目的Webflow的初始點)。 FlowExecutor可以訪問flowDefinitionRegistry,其中所有流都在註冊到請求之前註冊。

希望這會有所幫助。

+0

所以總結一下。如果提供了明確的ID,它就按原樣使用。如果不是默認情況下,除非定義了註冊表基本路徑,否則將爲流分配的註冊表標識符等於其文件名減去文件擴展名。如果提供基本路徑,則現在將爲流分配與其基本路徑和文件名之間的路徑段相同的註冊表標識符。 –