开发者

Spring Webflow, return to main flow from any sub-flow

开发者 https://www.devze.com 2023-03-01 14:26 出处:网络
I\'m trying to return to my main flow in spring, from any of my subflows just by clicking a button. when I use <end-state> it just goes to the previous flow, which is also开发者_运维知识库 a s

I'm trying to return to my main flow in spring, from any of my subflows just by clicking a button.

when I use <end-state> it just goes to the previous flow, which is also开发者_运维知识库 a sub-flow in the application.

Any ideas?


You just need the appropriate transitions in each subflow-state in the calling flow to do what you want. The end-state id in your subflow is what will be used as the event id you can transition on in your calling flow.

A subflow can be thought of as a branch of execution. So when your subflow is finished, control is returned back to the calling flow. Think of your end-state as a return statement (and the id attribute as the value returned -- you can also set output attributes but that is not important here).

When your subflow terminates, control is returned backed to the calling flow. The calling flow should define a transition that determines how to handle this event. The event id you will see is the id of the end-state in your subflow.

So in your subflow if you have the following end-state:

<end-state id="back"/>

You can then handle this transition in the flow that called the subflow:

<subflow-state id="do-some-sub" flow="some-sub">
    < ... input variables, expressions, etc ... />
    <transition on="back" to="some-state"/>
</subflow-state>

Note that some-state here can also be an end-state. Your situation sounds like you have a main flow that calls a subflow which in turn calls another subflow. So you would want some-state to be an end-state, which would then be handled by its calling flow (in your case the "main" flow).


You can achieve this by adding the 'parent' attribute when you define your sub flow like this

<flow parent="login" xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/webflow  http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">

<view-state id="forgotPassword">
        <transition on="backtoLogin" to="login">

        </transition>

here i want my subflow to return to the login page on a back button 'click' .

One thing to notice is that in your parent flow.xml u need to specify the absolute path of the view

my parent ie login-flow.xml is given below

<flow xmlns="http://www.springframework.org/schema/webflow"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/webflow     http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">


<view-state id="login" view="../login/defaultLogin.xhtml">
0

精彩评论

暂无评论...
验证码 换一张
取 消