Over a million developers have joined DZone.

JSF 2.2: Flow Calls

DZone's Guide to

JSF 2.2: Flow Calls

· Java Zone
Free Resource

Bitbucket is for the code that takes us to Mars, decodes the human genome, or drives your next car. What will your code do? Get started with Bitbucket today, it's free.

In this tutorial, we will consider Faces Flow calls. For a basic level of information about Faces Flow, please check out this article and, for information about the usage of flows, you can check out JSF 2.2: Use Faces Flow tutorial.

Here, we will expand the sample application from the previous tutorial in a way that will allow the customer and order flows to call each other. This way, when an order flow is called from a customer flow, the recorded customer’s name, surname and address information is passed as a parameter to the order flow. When a customer flow is called from an order flow, the order's product, price and billing address information is passed as a parameter to the customer flow. 

1. Project directory structure

Screen Shot 2013-06-30 at 8.45.34 PM

2. Project dependencies


3. Customer.java

public class Customer implements Serializable {
    public Flow defineFlow(@FlowBuilderParameter FlowBuilder flowBuilder) {

        String flowId = "customer";
        flowBuilder.id("", flowId);
        flowBuilder.viewNode(flowId, "/" + flowId + "/" + flowId + ".xhtml").markAsStartNode();
        flowBuilder.inboundParameter("productOrder", "#{flowScope.productOrder}");
        flowBuilder.inboundParameter("priceOrder", "#{flowScope.priceOrder}");
        flowBuilder.inboundParameter("adressLine1Order", "#{flowScope.adressLine1Order}");
        flowBuilder.inboundParameter("adressLine2Order", "#{flowScope.adressLine2Order}");
        flowBuilder.inboundParameter("cityOrder", "#{flowScope.cityOrder}");
        flowBuilder.inboundParameter("stateOrder", "#{flowScope.stateOrder}");
        flowBuilder.inboundParameter("postalCodeOrder", "#{flowScope.postalCodeOrder}");
        flowBuilder.inboundParameter("countryOrder", "#{flowScope.countryOrder}");
        flowBuilder.flowCallNode("callOrder").flowReference("", "order")
                   .outboundParameter("firstNameCustomer", "#{customerBean.firstName}")
                   .outboundParameter("lastNameCustomer", "#{customerBean.lastName}")
                   .outboundParameter("adressLine1Customer", "#{customerBean.adressLine1}")
                   .outboundParameter("adressLine2Customer", "#{customerBean.adressLine2}")
                   .outboundParameter("cityCustomer", "#{customerBean.city}")
                   .outboundParameter("stateCustomer", "#{customerBean.state}")
                   .outboundParameter("postalCodeCustomer", "#{customerBean.postalCode}")
                   .outboundParameter("countryCustomer", "#{customerBean.country}");
        return flowBuilder.getFlow();

The InboundParameter method adjusts the names and values of incoming parameters from the order flows.

The FlowCallNode method defines how a customer flow calls an order flow. The “callOrder” argument that was passed to the method defines the action of calling the flow. The chained flowReference method defines the actual name of the flow to call.

When the order flow is called, the outboundParameter method is called in order to define the parameters to be passed. 

For an explanation of the remaining code, you can check out the previous tutorial

4. order-flow.xml

<flow-definition id="order">
        <flow-return id="returnFromOrderFlow">
        <flow-call id="callCustomer">

In this code, the XML configuration is similar to the programmatic configuration. Incoming parameters for the order flow are defined with the inbound-parameter element. 

Flow-call elements define how an order flow will call a customer flow. The "callCustomer" argument that is passed to the ID attribute of the element defines the action of calling the flow

Flow-reference elements within the element defines the actual name of the flow for the call. When a customer flow is called, parameters to be passed are defined by the outboundParameter element. 

For an explanation of the remaining parts of the XML configuration, you can check out the previous tutorial. 

5. CustomerBean.java – OrderBean.java

public class CustomerBean implements Serializable {

    private String firstName;
    private String lastName;
    private String adressLine1;
    private String adressLine2;
    private String city;
    private String state;
    private String postalCode;
    private String country;
    public CustomerBean() {
        System.out.println("CustomerBean has been created...");
    public String getName() {
        return this.getClass().getSimpleName();

    public String getReturnValue() {
        return "/index";
 /* getter and setter methods */

6. Demo application

Bitbucket is the Git solution for professional teams who code with a purpose, not just as a hobby. Get started today, it's free.


Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}