Spring Webflow VS AngularJS

Spring Webflow VS AngularJS

我知道有人问过这个问题,但我似乎没有找到合适的答案。所以想再次提出问题。

我们需要构建一个响应式应用程序,我们的客户将使用它来创建订单。

我开始研究 Spring4 Webflow,甚至创建了一个示例比萨饼应用程序 [感谢 Spring in Action] 效果很好,因为我们需要我们的应用程序非常可扩展,这看起来像干得好。

我们遇到的问题是 - 我们在应用程序的其他任何地方都使用 AngularJS + Spring MVC/REST。 对于 WebFlow,看起来我们需要使用 spring 形式,即绑定是由 Spring 完成的,加上 angularJS 和 Spring WebFlow 之间的其他冲突。有没有一种方法可以同时使用 Spring WebFlow + AngularJS 我们利用 angular 全部潜力但仍然使用 WebFlow 来模仿对话行为?

createPizza.jsp

<form:form commandName="pizza">
      <input type="hidden" name="_flowExecutionKey" 
          value="${flowExecutionKey}"/>

顺序-flow.xml

<view-state id="createPizza" model="flowScope.pizza">
        <on-entry>
          <set name="flowScope.pizza" 
              value="new com.springinaction.pizza.domain.Pizza()" />

          <evaluate result="viewScope.toppingsList" 
              expression="T(com.springinaction.pizza.domain.Topping).asList()" />
        </on-entry>
        <transition on="addPizza" to="showOrder">
          <evaluate expression="order.addPizza(flowScope.pizza)" />
        </transition>
        <transition on="cancel" to="showOrder" />
    </view-state>

我认为 SWF 从未被设计为用作 SPA(单页应用程序)。 SWF 'state' 标签总是调用服务器并刷新整个页面以重新呈现视图。这从根本上与 AngularJS.

冲突

您可以选择在 SWF 中启用 ajax 请求,并在单个视图状态标记内仅呈现部分 html 片段。但现在的问题是您将在单个视图状态标记中拥有所有业务逻辑,这(在我看来)显着降低了使用 SWF 的优势并违反了 SRP 原则,但存在该选项。

查看此示例,详细解释 SWF ajax 请求的工作原理:

此外,请参阅文档了解如何启用 ajax requests/partial 片段:

http://docs.spring.io/spring-webflow/docs/current/reference/htmlsingle/#spring-js-ajax

从当前版本 2.5(可能还有一些旧版本)开始,看起来实际上可以将 Angular 应用程序与 SWF(Spring Web Flow)应用程序结合使用。 默认情况下,SWF 使用 post-redirect-get 方法来避免浏览器中后退按钮的问题(例如确认重新 posting 和操作的幂等性),但您可以覆盖此默认行为通过添加

mode=embedded

所有 Ajax 请求的参数,仅针对网络流的开始状态。

如文档中所述:

When launched in "page embedded" mode a flow will not issue flow execution redirects during Ajax requests. The mode=embedded parameter only needs to be passed when launching the flow. Your only other concern is to use Ajax requests and to render only the content required to update the portion of the page displaying the flow.

此处有更多详细信息:

Chapter 11.7 of the release 2.5: Embedding A Flow On A Page