2012-11-29 37 views
1

目前由於Post/Redirect/Get模式,所有流量URL類似於<site_url>/flow_name?execution=?,並且輸入GET參數未保留。因此,用戶不能複製網址或將其加入書籤。Spring Webflow 2和可加書籤的URL

任何建議怎麼會這樣整齊呢?

+2

我認爲用「流」的想法是,單個步驟對書籤沒有意義。如果他們這樣做了,他們應該在流程之外。也就是說,試圖將流程作爲一個整體加入書籤是很不幸的 - 這意味着回到開始的步驟 - 並不乾淨,因爲所有步驟的URL都有一些執行鍵。 – dbreaux

回答

0

你總是可以使用和書籤鏈接到你的流量的起點之一。
比如,你可以做<site_url>/flow_name?personId=123&projectId=456假設你有兩個輸入您的流量personIdprojectId。但你需要知道網址(你將不得不把它交給用戶),你不能使用地址欄上的那個。

即使你想這樣做,你也不能使用書籤鏈接到你的流程中的一個特定狀態(除非你在流程開始時添加一些邏輯來指導你到一個特定的事件取決於輸入的值)。

1

我們可以通過自定義SWF API的FlowHandlerAdapter來爲基於SWF的應用程序的URL添加書籤。

這裏有一個例子:

我的SWF的配置文件將有:

<bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController"> 
     <property name="flowHandlerAdapter" ref="customFlowHandlerAdapter" /> 
    </bean> 

    <bean id="customFlowHandlerAdapter" class="com.xyz.CustomFlowHandlerAdapter"> 
     <property name="flowExecutor" ref="flowExecutor" /> 
     <property name="flowUrlHandler" > 
      <bean class="com.xyz.CustomURLFlowHandler" /> 
     </property> 
    </bean> 

我CustomFlowHandlerAdapter將有:

public class CustomFlowHandlerAdapter extends FlowHandlerAdapter { 

... 

@Override 
    public ModelAndView handle(HttpServletRequest request, 
      HttpServletResponse response, Object handler) throws Exception { 
     FlowHandler flowHandler = (FlowHandler) handler; 
     checkAndPrepare(request, response, false); 
     String flowExecutionKey = this.getFlowUrlHandler() 
       .getFlowExecutionKey(request); 
     if (flowExecutionKey != null) 
      try { 
       ServletExternalContext context = createServletExternalContext(
         request, response); 
       FlowExecutionResult result = this.getFlowExecutor().resumeExecution(
         flowExecutionKey, context); 
       handleFlowExecutionResult(result, context, request, response, 
         flowHandler); 
      } catch(org.springframework.webflow.execution.repository.NoSuchFlowExecutionException ex){ 
       response.sendRedirect(request.getRequestURI()); 
      } catch(org.springframework.webflow.execution.repository.BadlyFormattedFlowExecutionKeyException ex){ 
       response.sendRedirect(request.getRequestURI()); 
      } catch (FlowException e) { 
       handleFlowException(e, request, response, flowHandler); 
      } 
.... 

這裏蔭醒目NoSuchFlowExecutionException和我重定向到確切的流沒有任何參數的網址。在這裏,您可以捕獲並重新包含您的參數

因此,我能夠從任何狀態爲書籤我的URL(始終從第一個流程開始),如果需要,我也能夠發送自己的參數。