Performance Zone is brought to you in partnership with:

I started my software adventure with GWBasic programming language. I met with Visual Basic language after QuicBasic and I developed many applications with it until 2000. I stepped into the world of web with PHP. After that, my path crossed with Java! I have been developing enterprise applications with Java EE Technologies since 2005. JavaServer Faces and Spring frameworks are in my area of expertise. I’m trying to specialize in NoSQL Technologies. Hüseyin has posted 13 posts at DZone. You can read more from them at their website. View Full User Profile

JSF 2.2: Flow Calls

  • submit to reddit
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



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

        String flowId = "customer";"", 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", "#{}")
                   .outboundParameter("stateCustomer", "#{customerBean.state}")
                   .outboundParameter("postalCodeCustomer", "#{customerBean.postalCode}")
                   .outboundParameter("countryCustomer", "#{}");
        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. –

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

Published at DZone with permission of its author, Hüseyin Akdoğan. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)