(Quick Reference)

1 Introduction - Reference Documentation

Authors: Graeme Rocher

Version: 2.1.0

1 Introduction

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 Webflow is no longer in Grails core, so you must install the Webflow plugin to use this feature.

Creating a Flow

To create a flow create a regular Grails controller and 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.