Custom AttributeMappers
If the default implementation (org.springframework.webflow.support.
ParameterizableFlowAttributeMapper) is not sufficient, you can provide your own implemen-
tation of org.springframework.webflow.FlowAttributeMapper. Listing 12-9 provides a listing
for a custom implementation of FlowAttributeMapper, which performs the same function.
Listing 12-9.Implementation of ShippingAttributeMapper
public final class ShippingAttributeMapper implements FlowAttributeMapper {
public Map createSubflowInput(RequestContext requestContext) {
Map map = new HashMap();
Purchase purchase = (Purchase)➥
requestContext.getFlowScope().get("purchase");
map.put("requiresShipping", purchase.isRequiresShipping());
return map;
}
public void mapSubflowOutput(Map subflowOutput, RequestContext requestContext) {
Shipping shipping = (Shipping) subflowOutput.get("shipping");
Purchase purchase = (Purchase)➥
requestContext.getFlowScope().get("purchase");
purchase.setShipping(shipping);
}
}
The attribute mappings in the subflow state in /WEB-INF/flows/purchase-flow.xmlwould
now change to
■Tip You can plug in a custom AttributeMapperusing the beanattribute. Many other constructs support
pluggability in this fashion. Search for the beanattribute within the spring-webflowDTD to review them.
Inline Flows
Subflows are a very powerful construct within Spring Web Flow; they allow you to encapsulate
and reuse page navigation logic in multiple contexts. One consequence of extracting a flow to
be used as a subflow is that the extracted flow becomes usable as a top-level, or first-class,
flow. This level of exposure may not always be desirable. For example, a particularly complex
process that is composed of multiple logical subprocesses may benefit from being partitioned
into separate flows, even if those flows will never be needed outside of the parent flow. The
appropriate construct for this scenario is an inlineflow.
CHAPTER 12 ■ADVANCED SPRING WEB FLOW 343