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

好久不见. 提交于 2019-12-10 19:56:08

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/227532/how-do-i-pass-model-data-beween-a-view-state-and-action-state-in-spring-web-flow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!