简体   繁体   English

如何在Spring Web Flow 2中的视图状态和操作状态之间传递模型数据

[英]How do I pass model data beween a view state and action state in Spring Web Flow 2

In the Web Flow below I bind form data to a flow variable (lifeCycleForm) on a submit event in the view state. 在下面的Web Flow中,我将表单数据绑定到视图状态中的submit事件的流变量(lifeCycleForm)。 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. 但是,当评估动作状态中的表达式时,所有三个属性都为null。 My form bean is serializable and I am just using simple string properties. 我的表单bean是可序列化的,我只是使用简单的字符串属性。

What I am doing wrong? 我做错了什么?

I am pretty new to Spring WebFlow so I might have missed something obvious. 我对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" />

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. 我已经了解到AbstractFlowExecutionTests没有实现请求参数的绑定。 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 2.0.4并且行为保持不变。

Update: My problems are that Spring WebFlow mocks do not simulate form submission. 更新:我的问题是Spring WebFlow模拟不模拟表单提交。

Thanks in advance, Brian 布莱恩,提前谢谢

To much chagrin, I also recently found out that the Webflow testing mocks don't use Spring's binding. 令我非常懊恼的是,我最近还发现Webflow测试模拟不使用Spring的绑定。 Have you tried running the flow using debugging in a container like Tomcat from within an IDE like Eclipse ? 您是否尝试过使用像Tomcat这样的容器中的调试来运行流程? 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. 如果您需要帮助,我可以提供进一步的提示,但是首先我要说下载Eclipse Web标准工具和Web工具项目插件(如果您还没有)。

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 Webflow 1 FormActions绑定到模型对象,即使它会使您的流程稍微冗长。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM