Back Forum Reply New

Subflows and Exception handling

Hello All,   I am new to Webflows. Just beginnning to have a handon on the webflows. I had a question on the exception handling in Subflows.

I have a parent webflow which calls a subflow. This Parent webflow has a view-state and it calls a subflow. An action bean from a subflow throws an exception which I need to show in the parent webflow's view-state.

Which is a good way of handling the these kind of exceptions from the subflows?

Cheers,
Nitin

Hi,
I am also have the same problem. Has anyone figured it out?
Thanks,
Basheer.

In case it is an Exception which you can catch within a Flow execution you could implement a FlowExecutionListener (subclass FlowExecutionListenerAdapter):Code:
public void exceptionThrown(RequestContext context, FlowExecutionException exception) {
String info=quot;Called when an exception is thrown during a flow execution, before the exception is handled by any registered handler.\nquot;;
if(!context.getFlowExecutionContext().getActiveSession().isRoot())
context.getFlowExecutionContext().getActiveSession().getParent().getScope().put(quot;keyquot;, quot;messagequot;);

logger.log(Level.INFO, info);
}
to put a message into the flow scope of the parent.

In your subflow you could use the on-exception attribute and transition to an exception end state on which outcome you listen on the parent flow.

Just an idea.

- Peter

I have not tested this in a parent flow from a subflow, but based upon the JavaDoc comments for the TransitionExecutingFlowExecutionExceptionHandler class, both the flowExecutionException and the rootCauseException should be available in the flash scope, which means it should be accessible in the parent flow.

Here's an excerpt:

Code:
/*** A flow execution exception handler that maps the occurrence of a specific type of exception to a transition to a new* {@link org..webflow.engine.State}.* lt;pgt;* The handled {@link FlowExecutionException} will be exposed in flash scope as* {@link #FLOW_EXECUTION_EXCEPTION_ATTRIBUTE}. The underlying root cause of that exception will be exposed in flash* scope as {@link #ROOT_CAUSE_EXCEPTION_ATTRIBUTE}.* * @author Keith Donald*/
public class TransitionExecutingFlowExecutionExceptionHandler implements FlowExecutionExceptionHandler {

private static final Log logger = LogFactory.getLog(TransitionExecutingFlowExecutionExceptionHandler.class);

/*** The name of the attribute to expose a handled exception under in flash scope (quot;flowExecutionExceptionquot;).*/
public static final String FLOW_EXECUTION_EXCEPTION_ATTRIBUTE = quot;flowExecutionExceptionquot;;

/*** The name of the attribute to expose a root cause of a handled exception under in flash scope* (quot;rootCauseExceptionquot;).*/
public static final String ROOT_CAUSE_EXCEPTION_ATTRIBUTE = quot;rootCauseExceptionquot;;
I have used this to access the exceptions in my error.jsp page like this:

Code:
lt;divgt;
lt;h4gt;An error occurred.lt;/h4gt;
lt;c:choosegt;
lt;c:when test=quot;${rootCauseException.class.simpleName eq 'NullPointerException'}quot;gt;
You have hit a null pointer!!
lt;/c:whengt;
lt;c:when test=quot;${rootCauseException.class.simpleName eq 'UsernameNotFoundException'}quot;gt;
lt;pgt;
Sorry, the username you are using has not been setup in the system.  Please setup the user properly and try again.
lt;/pgt;
lt;pgt;
Exception message is: ${rootCauseException.message}
lt;/pgt;
lt;/c:whengt;
lt;ctherwisegt;
You got some other error!!
lt;/ctherwisegt;
lt;/c:choosegt;
lt;/divgt;
Hope that helps!
¥
Back Forum Reply New