Tuesday, October 25, 2011

Using Spring WF's FlowExecutionExceptionHandler

This powerful feature allows webflow states to intercept exceptions and redirect accordingly.

To use the handler simple use the global transitions in flow:
(I choose a global or parent one so my concerned flows can inherit it)

<global-transitions>
<transition
on-exception="org.springframework.ws.soap.client.SoapFaultClientException"
to="soapFaultClientException" />
</global-transitions>

This will then allow the inherited by other flows or you can dump it into the flow you need

<flow parent="global"...

Within the (child) flow or any flow that the global transition apply to, handle the transition
<subflow-state id="soapFaultClientException" subflow="exception/soap">
<transition on="end" to="search" />
</subflow-state>

The controller or view will have access to the exception details via the root cause object
<on-start>
<evaluate expression="controller.prepareErrorMessage(rootCauseException)" />
</on-start>

which is of type
public void prepareErrorMessage(SoapFaultClientException ex){
...
}

Finally the JSF can access the error or exception within the controller

No comments:

Post a Comment