gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:20:36 24 4
gpt4 key购买 nike

在下面的 Web Flow 中,我将表单数据绑定(bind)到 View 状态中提交事件的流变量 (lifeCycleForm)。我已验证名称、标签和描述属性均按预期填充。

但是,当计算 Action 状态中的表达式时,所有三个属性都为空。我的表单 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 没有实现请求参数的绑定(bind)。这对我来说似乎有点疏忽。我已经尝试了最新的 nightly Spring WebFlow 2.0.4,并且行为保持不变。

更新:我的问题是 Spring WebFlow 模拟不模拟表单提交。

提前致谢,布莱恩

最佳答案

令我非常懊恼的是,我最近还发现 Webflow 测试模拟不使用 Spring 的绑定(bind)。您是否尝试过在 Eclipse 等 IDE 中使用 Tomcat 等容器中的调试来运行流程?如果你还没有,它会非常有用。如果您需要帮助,我可以提供更多提示,但首先我建议您下载 Eclipse Web Standard Tools 和 Web Tools Project 插件(如果您还没有的话)。

请注意,如果您真的希望能够对绑定(bind)进行单元测试,您仍然可以使用 Spring Webflow 1 FormActions 绑定(bind)到模型对象,尽管这会使您的流程稍微冗长一些。

关于java - 如何在 Spring Web Flow 2 中的 View 状态和操作状态之间传递模型数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/227532/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com