Programmatically Start A JSF Flow

1 minute read

There are situations where you can not start a JSF (2.2) flow in the usual way by simply redirecting to the flow’s start page from your button action.

This is for example the case when you want to start a JSF flow from e.g. a view action method. In this case it is not sufficient to simple return the view name of the flow as this will not just start it.

To properly start the flow you need to first tell the flow handler that you are now transitioning into a flow. You can do this with the following code:

If done like this, that flow should start as expected. However, if you don’t set up the FlowHandler.transition properly you will end up with the following error:

WELD-001303: No active contexts for scope type javax.faces.flow.FlowScoped

Note: You need to reach the page running the view action through a GET request. So using the normal h:commandButton will not work in this case as this issues a POST request (except you add ?faces-redirect=true to your action parameter of course).

The full source for this example can be found here.

Updated: