如何在 Spring Web Flow 2 中的视图状态和操作状态之间传递模型数据
在下面的 Web Flow 中,我将表单数据绑定到视图状态下提交事件上的流变量 (lifeCycleForm)。 我已验证名称、标签和描述属性均按预期填充。
然而,当计算动作状态中的表达式时,所有三个属性都为空。 我的表单 bean 是可序列化的,我只使用简单的字符串属性。
我做错了什么?
我对 Spring WebFlow 还很陌生,所以我可能错过了一些明显的东西。
<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 没有实现请求参数的绑定。 这对我来说似乎有点疏忽。 我已经尝试过最新的 nightly Spring WebFlow 2.0.4,行为保持不变。
更新: 我的问题是 Spring WebFlow 模拟不模拟表单提交。
提前致谢, 布莱恩
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.
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.
What I am doing wrong?
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" />
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.
Update: My problems are that Spring WebFlow mocks do not simulate form submission.
Thanks in advance,
Brian
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
令我懊恼的是,我最近还发现 Webflow 测试模拟不使用 Spring 的绑定。 您是否尝试过在 Eclipse 等 IDE 中的 Tomcat 等容器中使用调试来运行流程? 如果你还没有,它将非常有用。 如果您需要帮助,我可以提供更多提示,但首先,如果您还没有下载 Eclipse Web Standard Tools 和 Web Tools Project 插件,我建议您先下载。
顺便说一句,如果您确实希望能够对绑定进行单元测试,您仍然可以使用 Spring Webflow 1 FormActions 绑定到模型对象,尽管这会使您的流程稍微冗长一些。
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.
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.