SWF 2.0 - Backtracking and exception catching
Hi,
We have a problem with using back buttons in SWF 2.0. Backtracking inside one flow works fine until history=”invalidate/discard” attribute is used. When back button reach the invalid view the “SnapshotNotFound“ error occurs. Is it possible to catch this error and refresh the last valid page with useful message?
With extending “AbstractFlowHandler” it is possible to handle that but only redirect is possible (request context is no longer available) but message could not be shown.
PHP Code:
@Override
public String handleException(FlowException e, HttpServletRequest request,
HttpServletResponse response)
{
if (e instanceof FlowExecutionRestorationFailureException)
{
if (e.getCause() instanceof SnapshotNotFoundException)
{
return getFlowId();
}
}
return super.handleException(e, request, response);
}
When customizing “SimpleMappingExceptionResolver” only catches the exception occurred during user event.
PHP Code:
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<prop key="FlowExecutionRestorationFailureException">Login</prop>
</props>
</property>
</bean>
Are there any other alternatives to catch errors which do not occur during user event?
Thanks,
Jaka, Tomi
SWF 2.0 - Backtracking and exception catching: a work around
We have implemented the following workaround:
We extended the "AbstractFlowHandler" as follows:
PHP Code:
public class ExceptionHandlingFlowHandler extends AbstractFlowHandler {
@Override
public String handleException(FlowException e, HttpServletRequest request, HttpServletResponse response) {
if (e instanceof FlowExecutionRestorationFailureException) {
try {
response.sendRedirect("next.jspx");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return null;
} else {
return super.handleException(e, request, response);
}
}
}
In WEB-INF we put next.jspx:
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script type="text/javascript">
function forward(){
location.href="javascript: history.go(1)";
}
</script>
</head>
<body onload="setTimeout('forward()',0)"/>
</html>
So when a user clicks the backbutton and the page the browser wants to send him to is invalid because of history=”invalidate/discard”, he is forwarded back to where he came from.
Maybe not the prettiest way but for us it works fine :)