## 6.5 Web Flow

#### Overview

Grails supports the creation of web flows built on the Spring Web Flow project. A web flow is a conversation that spans multiple requests and retains state for the scope of the flow. A web flow also has a defined start and end state.

Web flows don't require an HTTP session, but instead store their state in a serialized form, which is then restored using a flow execution key that Grails passes around as a request parameter. This makes flows far more scalable than other forms of stateful application that use the HttpSession and its inherit memory and clustering concerns.

Web flow is essentially an advanced state machine that manages the "flow" of execution from one state to the next. Since the state is managed for you, you don't have to be concerned with ensuring that users enter an action in the middle of some multi step flow, as web flow manages that for you. This makes web flow perfect for use cases such as shopping carts, hotel booking and any application that has multi page work flows.

> From Grails 1.2 onwards you must install the Webflow plugin to use this feature: `grails install-plugin webflow`

#### Creating a Flow

To create a flow create a regular Grails controller and then add an action that ends with the convention `Flow`. For example:

    class BookController {
       def index = {
          redirect(action:"shoppingCart")
       }
       def shoppingCartFlow = {
            …
       }
    }

Notice when redirecting or referring to the flow as an action we omit the `Flow` suffix. In other words the name of the action of the above flow is `shoppingCart`.