javaspringspring-webflow

Get the ids of the previously executed states in spring web flow


In my Spring Webflow application, I am trying to show the list of ids of executed states (from start) (view-state and action-state) at a current point. So, is there a method in Java, which I can use to get this information?

Thank you


Solution

  • I would suggest setting up and using a FlowExecutionListener, specifically the methods sessionStarted, stateEntered and sessionEnded

    you can get the id of a state using context.getCurrentState().getId()

    public class MyFlowListener implements FlowExecutionListener {
    
        @Override
        public void stateEntered(RequestContext context, StateDefinition previousState, StateDefinition state) {
    
        }
    
        @Override
        public void sessionStarted(RequestContext context, FlowSession session) {
    
        }
    
        @Override
        public void sessionEnded(RequestContext context, FlowSession session, String outcome, AttributeMap<?> output) {
    
        }
    }
    

    you can register your listener like this (xml config):

    <bean id="myFlowListener" class="my.custom.webflow.MyFlowExecutionListener"/>
    
    <webflow:flow-executor id="flowExecutor">  
        <webflow:flow-execution-listeners>  
            <webflow:listener ref="myFlowListener"/>  
        </webflow:flow-execution-listeners>  
    </webflow:flow-executor>