springspring-webflow

How could this spring webflow action state executed?


I saw a spring web flow like this. As you could see, there are two view states and both of them will be called by links outside this flow. But I have no idea why each time this flow is activated, the action state will always be called. I personally think there should be an on-entry tag. Any thoughts? I appreciate your help.

  <?xml version="1.0" encoding="UTF-8"?>
    <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.xsd">

        <action-state id="start">
            <evaluate expression="aaa.fsdf()"/>
            <evaluate expression="aaa.bbb()"/>
            <transition on="yes" to="viewone"/>
            <transition on="no" to="viewtwo"/>
        </action-state>

        <view-state id="viewone" view="web/ccc">
        </view-state>

        <view-state id="viewtwo" view="web/eee">
        </view-state>


        <end-state id="final" view="web/final">
        </end-state>

    </flow>

Solution

  • this is how flows work in Spring Webflow. see documentation about flows

    The first state defined becomes the flow's starting point.


    Also, you cannot directly call a state within a flow directly. Let's say your flow is name "test-flow", in a file called test-flow.xml

    when you call the flow via URL, using yoursite.com/test-flow it will enter the flow and the first state of the flow. so if you want to call a specific view state within the flow, you have to use some logic to direct the flow into the state you want. One way to do this is to pass a parameter, like yoursite.com/test-flow?test=1 and in your flow, use an action state to check for that parameter and transition to the proper view-state.

    This is what is happening here, the action state in your flow is the starting point, and based on some logic it will transition to your viewone or viewtwo.

    Hope this makes sense