简要说明:
我认为您通常误解了“视图状态”和 Spring webflow 的预期目的。
Spring Webflow = 一个 xml 文件,描述了实现单一目标的状态的“顺序”逻辑流(例如,“预订机票”、“收集烹饪收据的信息”等。 ..)
“顺序”在这里表示每个单独的状态(例如视图状态、操作状态、决策状态、结束状态)都是一个执行的单个单元在 Spring 网络流中。每个状态明确定义完成执行后“下一个”状态将是什么。例如,
(view-state A) -> (action-state B) -> (decision-state C) -> (end-state D)
在每个状态中都没有定义迭代的概念,因为它们是单个执行单元。一旦一个状态完成执行,它必须进入由“transition”标签定义的下一个状态。
<view-state id="stateA">
<transition to="stateB"/>
</view-state>
还请注意,我在引号中写了“顺序”,因为尽管流程是顺序的(从状态 -> 状态)......我们仍然可以像这样跳回到我们希望的任何状态。
(view-state A) -> (action-state B) -> (decision-state C) -> (view-state A)
所以...您对内部视图状态迭代的解释不存在。
回答您的问题:
有几种方法可以实现您想要的“状态”迭代,但听起来您需要一个决策状态来根据一些 flowScope 变量委托流程。基本上,您想跟踪要执行特定状态的次数,然后每次执行该状态时,您将变量递减 (1) 并重新评估它,直到执行次数 == 0。
下面定义的示例流程与 cmets(不是基于您的描述中的示例代码)。
<!-- define the 'global' flowScope variable that will track the num of times you want to execute the ingredients state -->
<set name="flowScope.numOfTimesToExecuteIngredientsState" value="0" type="java.lang.Integer"/>
<view-state id="basicInfoState" model="basicInfoModel">
<!-- initially goto the decision state and make sure to set the num of execution inside the transition to the 'global' flowScope tracking variable -->
<transition on="save" to="ingredientsIteratorDecisionState">
<!-- assuming ingredients is an initialized Set<Ingredients>... get the size and put inside a flowScope var -->
<set name="flowScope.numOfTimesToExecuteIngredientsState" value="basicInfoModel.getIngredients().size()"/>
</transition>
</view-state>
<decision-state id="ingredientsIteratorDecisionState">
<!-- if # of executions is more than 0 go back to ingredientState otherwise move on to instructionsState -->
<if test="flowScope.numOfTimesToExecuteIngredientsState > 0" then="ingredientsState" else="instructionsState"/>
</decision-state>
<view-state id="ingredientsState">
<transition on="save" to="ingredientsIteratorDecisionState">
<! -- upon a successful save... decrement numOfIngredientsSelected by ( 1 ) -->
<set name="flowScope.numOfTimesToExecuteIngredientsState" value="flowScope.numOfTimesToExecuteIngredientsState - 1"/>
</transition>
</view-state>
免责声明:上述流程定义未经测试。我只是凭记忆写的。可能存在语法错误。
你还问过:
或者,有没有办法在 webflow.xml 中设置
可以在视图#1 jsp 表单中更新,然后在视图#2 中进行评估
不调用服务器函数?或者正在使用并输出一个
可能的解决方案?或者我可以使用请求参数吗?
没有。将始终调用服务器。为什么不直接从存储在模型中的集合对象的大小推断出配方的数量?
您可以enable SWF the handling of ajax requests 并将 requestParam 发送到未定义“to=”状态的转换。 (意味着它将保持当前视图状态)并在转换标签内执行您的自定义逻辑(请参阅:How to include a pop-up dialog box in subflow)
但我认为这是一个设计问题。您传递的所有值都应该在一个 http 请求中(因此是模型的一部分)。