I have recently upgraded from RC1 to 1.0, and I ran into an issue with how the errors are now stored in flash scope and a redirect is done before entering a view-state. I have a flow where errors are "stored" while in a subflow, and then execution ends the subflow and a view-state in the parent flow is entered. In the below example, the execution would be:
parentView -> parentSubflow (myInlineFlow) -> inlineAction <error event> -> inlineErrorState -> parentView
The errors are stored while in a method call in the inlineAction state and when the end-state is hit in the subflow, flashScope dies (which makes sense since the flash is tied to events fired in the flow). When we get to parentView for the second time, the flash (and therefore the errors) are gone. This worked in RC1 because the errors were stored in request scope, which would live even when the subflow died.Code:<flow> ... <view-state id="parentView" view="foo.bar"/> <subflow-state id="parentSubflow" flow="myInlineFlow"> ... <transition on="inlineErrorState" to="parentView"/> </subflow-state> ... <inline-flow id="myInlineFlow"> <flow> ... <action-state id="inlineAction"> ... <transition on="error" to="inlineErrorState"/> </action-state> ... <end-state id="inlineErrorState"/> </flow> </inline-flow> ... </flow>
Turning off redirect before view-state wasn't an option and neither was re-writing the flow to not have this funky relationship, nor was changing the scope of the errors. My (admittidly hacky) solution is to explicitly map the errors between the parent and subflow.
Code:<flow> ... <view-state id="parentView" view="foo.bar"/> <subflow-state id="parentSubflow" flow="myInlineFlow"> <attribute-mapper> <output-mapper> <mapping source="errors" target='flashScope["org.springframework.validation.BindException.currentFormObject"]'/> </output-mapper> </attribute-mapper> ... <transition on="inlineErrorState" to="parentView"/> </subflow-state> ... <inline-flow id="myInlineFlow"> <flow> ... <action-state id="inlineAction"> ... <transition on="error" to="inlineErrorState"/> </action-state> ... <end-state id="inlineErrorState"> <output-mapper> <mapping source='flashScope["org.springframework.validation.BindException.currentFormObject"]' target="errors"/> </output-mapper> </end-state> </flow> </inline-flow> ... </flow>
Has anyone else ran into this problem? What was your solution? I like how my solution only required changing the flow definition, but I'm open to suggestions about the "right" way to solve this problem.


Reply With Quote