Spring Web Flow Application Beans
To understand more fully what's going on in Listing 3 and in the application itself, we must review the main bean definitions. The latter are defined in the file itemlist-servlet.xml illustrated in Listing 4. Most of the bean entities in Listing 4 are simply infrastructure elements required by Spring web flow applications. The others are specific to the itemlist application.
Listing 4 The file itemlist-serlvet.xml.
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="alwaysUseFullPath" value="true" /> <property name="mappings"> <value>/app/**/**=flowController</value> </property> </bean> <!-- Exposes web flows for execution at a single request URL. The id of a flow to launch should be passed in by clients using the "_flowId" request parameter: e.g. /app/itemlist --> <bean id="flowController" class="org.springframework.webflow.executor.mvc.FlowController"> <property name="flowExecutor" ref="flowExecutor" /> <property name="argumentHandler"> <bean class="org.springframework.webflow.executor.support.RequestPathFlowExecutorArgumentHandler" /> </property> </bean> <!-- Launches new flow executions and resumes existing executions: Spring 1.2 config version --> <bean id="flowExecutor" class="org.springframework.webflow.config.FlowExecutorFactoryBean"> <property name="definitionLocator" ref="flowRegistry"/> </bean> <!-- Creates the registry of flow definitions for this application: Spring 1.2 config version --> <bean id="flowRegistry" class="org.springframework.webflow.engine.builder.xml.XmlFlowRegistryFactoryBean"> <property name="flowLocations"> <list> <value>/WEB-INF/itemlist.xml</value> <value>/WEB-INF/itemlist-alternate.xml</value> </list> </property> </bean> <!-- Resolves flow view names to .jsp templates --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean> <bean id="createItemAction" class="org.springframework.webflow.samples.itemlist.NewItemAction" /> <bean id="addItemAction" class="org.springframework.webflow.samples.itemlist.AddItemAction" />
Notice the following two lines in Listing 4:
<value>/WEB-INF/itemlist.xml</value> <value>/WEB-INF/itemlist-alternate.xml</value>
These are the XML files that describe the navigational state logic for the application. In fact, we've already seen the contents of itemlist.xml in Listing 3. These two XML files are referenced in the file itemlist-serlvet.xml because they then become elements in the registry of flow definitions for the application. Also of interest in Listing 4 are the following two lines:
<bean id="createItemAction" class="org.springframework.webflow.samples.itemlist.NewItemAction" /> <bean id="addItemAction" class="org.springframework.webflow.samples.itemlist.AddItemAction" />
The two beans createItemAction and addItemAction are integrated into the flow. When the createItemAction bean returns "success", this results in a transition to the next state; that is, from displayItem to createItem. Spring web flow cleverly bridges between your JSP pages, your state definitions, and your backend code.