Listing 12-16.org.springframework.webflow.execution.FlowExecutionListener
public interface FlowExecutionListener {
void requestSubmitted(RequestContext context);
void requestProcessed(RequestContext context);
void sessionStarting(RequestContext context, State startState, Map input)
throws EnterStateVetoException;
void sessionStarted(RequestContext context);
void eventSignaled(RequestContext context, State state);
void stateEntering(RequestContext context, State nextState)
throws EnterStateVetoException;
void stateEntered(RequestContext context, State previousState, State state);
void resumed(RequestContext context);
void paused(RequestContext context, ViewSelection selectedView);
void sessionEnding(RequestContext context);
void sessionEnded(RequestContext context, FlowSession endedSession);
}
Implementing a FlowExecutionListenerallows you to weave in behavior in an
interceptor-like way. For example, you could provide a SecurityFlowExecutionListener
implementation that throws an EnterStateVetoExceptionpreventing a state from entering
if the user does not have the necessary permissions. You might develop listeners to apply
custom auditing, breadcrumbs (navigation history), or transactional behavior and so on.
■Tip For convenience Spring Web Flow provides an empty FlowExecutionListenerimplementation,
org.springframework.webflow.execution.FlowExecutionListenerAdapter.
Listeners are attached to a FlowExecution via anorg.springframework.webflow.execution.
FlowExecutionListenerLoader.The FlowExecutionListenerLoaderinfrastructure allows you to
define which FlowExecutionListenersapply to which flow definitions. Spring Web Flow provides
an org.springframework.webflow.manager.ConditionalFlowExecutionListenerLoaderimplemen-
tation for convenience, which is registered with the FlowExecutionManagerimplementation.
Listing 12-17 shows how to amend the flowExecutionManagerdeclaration to attach a
collection of listeners to executions of all flow definitions.
Listing 12-17.XML Fragment to Register a Number of FlowExecutionListeners
<bean id="flowExecutionManager"➥
class="org.springframework.webflow.manager.FlowExecutionManagerImpl">
<constructor-arg ref="flowRegistry"/>
<property name="listenerLoader">
<bean
class="org.springframework.webflow.manager.ConditionalFlowExecutionListenerLoader">
<property name="listeners">
352 CHAPTER 12 ■ADVANCED SPRING WEB FLOW