如何在Spring Web Flow 2中的视图状态和操作状态之间传递模型数据 [英] How do I pass model data beween a view state and action state in Spring Web Flow 2
问题描述
在下面的Web Flow中,我将表单数据绑定到视图状态中的submit事件的流变量(lifeCycleForm)。我已经验证了名称,标签和描述属性都按预期填充。
In the Web Flow below I bind form data to a flow variable (lifeCycleForm) on a submit event in the view state. I have verified that the name, label and description properties are all populated as expected.
但是,当评估动作状态中的表达式时,所有三个属性都为null。我的表单bean是可序列化的,我只是使用简单的字符串属性。
However, when the expression in the action state is evaluated all three properties are null. My form bean is serializable and I am just using simple string properties.
我做错了什么?
我是Spring WebFlow的新手,所以我可能错过了一些明显的东西。
I am pretty new to Spring WebFlow so I might have missed something obvious.
<var name="lifeCycleForm" class="com.btmatthews.freelancer.lifecycle.portlet.LifeCycleForm" />
<view-state id="createLifeCycle" model="lifeCycleForm">
<binder>
<binding property="name" required="true" />
<binding property="label" required="true" />
<binding property="description" required="false" />
</binder>
<transition on="submit" to="createLifeCycleAction" />
<transition on="cancel" to="lifeCycleCreationCancelled" bind="false" />
</view-state>
<action-state id="createLifeCycleAction">
<evaluate expression="lifeCycleService.createLifeCycle(lifeCycleForm.name, lifeCycleForm.label, lifeCycleForm.description, null, null)" />
<transition on="success" to="lifeCycleCreated" />
<transition on="failure" to="createLifeCycle" />
</action-state>
<end-state id="lifeCycleCreated" />
<end-state id="lifeCycleCreationCancelled" />
更新:我在原始帖子中忽略了提到它是我的失败的单元测试。我已经了解到AbstractFlowExecutionTests没有实现请求参数的绑定。这对我来说似乎有些疏忽。我已经尝试了最新的每晚Spring WebFlow 2.0.4并且行为保持不变。
Update: I neglected to mention in my original posting that it was my unit tests that were failing. I have since learned that AbstractFlowExecutionTests does not implement binding of request parameters. This seems like a bit of an oversight to me. I have tried latest nightly Spring WebFlow 2.0.4 and the behaviour remains the same.
更新:我的问题是Spring WebFlow模拟没有模拟表单提交。
Update: My problems are that Spring WebFlow mocks do not simulate form submission.
提前致谢,
Brian
Thanks in advance, Brian
推荐答案
我非常懊恼,最近我发现Webflow测试模拟不使用Spring的绑定。您是否尝试过使用像Tomcat这样的容器中的调试来运行流程?如果你没有,那将非常有用。如果您需要帮助,我可以提供进一步的提示,但是首先我要说下载Eclipse Web标准工具和Web工具项目插件(如果您还没有。)
To much chagrin, I also recently found out that the Webflow testing mocks don't use Spring's binding. Have you tried running the flow using debugging in a container like Tomcat from within an IDE like Eclipse ? If you haven't, it'll be very useful. If you need help, I can provide further tips, but to start I'd say download the Eclipse Web Standard Tools and Web Tools Project plugins if you haven't already.
作为旁注,如果您真的希望能够进行单元测试绑定,您仍然可以使用Spring Webflow 1 FormActions绑定到模型对象,即使它会使您的流程稍微冗长。
Just as a side note, if you really want to be able to unit test binding, you can also still use the Spring Webflow 1 FormActions to bind to the model object, even though it will make your flow slightly more verbose.
这篇关于如何在Spring Web Flow 2中的视图状态和操作状态之间传递模型数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!