流转定义实现如下:
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-1.0.xsd">
<var name="sale" class="org.springframework.webflow.samples.sellitem.Sale"/>
<start-state idref="enterPriceAndItemCount"/>
<view-state id="enterPriceAndItemCount" view="priceAndItemCountForm">
<transition on="submit" to="enterCategory"/>
</view-state>
<view-state id="enterCategory" view="categoryForm">
<transition on="submit" to="requiresShipping"/>
</view-state>
<decision-state id="requiresShipping">
<if test="${flowScope.sale.shipping}" then="enterShippingDetails" else="finish"/>
</decision-state>
<view-state id="enterShippingDetails" view="shippingDetailsForm">
<transition on="submit" to="finish"/>
</view-state>
<end-state id="finish" view="costOverview"/>
</flow>
用Spring Web Flow和Terracotta搭建Web应用(5)
时间:2011-02-05 infoq Jonas Bonér & Eu
我们从上面的定义可以看到,实际状态与状态图中的状态对应,状态转换与图中的箭头对应。"sale" bean是流转开始时分配的流转变量实例。它持有了Sale相关的属性。
上面的定义展示了所有的导航逻辑,但还没有实现任何应用行为。特别是在用户提交时更新Sale Bean的逻辑还没有实现。另外后台的sale处理逻辑还没有定义。
实现了所有必需行为的完整Spring Web Flow定义如下:
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-1.0.xsd">
<var name="sale" class="org.springframework.webflow.samples.sellitem.Sale"/>
<start-state idref="enterPriceAndItemCount"/>
<view-state id="enterPriceAndItemCount" view="priceAndItemCountForm">
<render-actions>
<action bean="formAction" method="setupForm"/>
</render-actions>
<transition on="submit" to="enterCategory">
<action bean="formAction" method="bindAndValidate">
<attribute name="validatorMethod" value="validatePriceAndItemCount"/>
</action>
</transition>
</view-state>
<view-state id="e
|