The Faces Flows programmatic interface
The Faces Flows are powered by CDI. It is possible to write programmatic flows by declaring a POJO that produces a Faces Flow. In order to generate a flow dynamically, we must annotate a bean as a CDI producer and generate a flow instance.
Here is a basic SimpleFlowFactory
class that supplies a Faces Flow:
import javax.faces.flow.builder.*; public class SimpleFlowFactory implements Serializable { @Inject DocumentIdGenerator generator; @Produces @FlowDefinition public Flow createFlow( @FlowBuilderParameter FlowBuilder flowBuilder) { final String documentId = generator.generate(); flowBuilder.id(documentId, "simpleFlow"); flowBuilder.viewNode("simpleFlow", "/simpleFlow/simpleFlow.xhtml") .markAsStartNode(); return flowBuilder.getFlow(); } }
We will annotate the createFlow()
method as a CDI producer with the special qualifier, @FlowDefinition
. We will also supply this method with...