AttributeMappers
The org.springframework.binding.AttributeMapper, shown in Listing 12-8, is a generic serv-
ice interface for mapping attributes from one source to another. Spring Web Flow uses it to
map objects and properties from one flow to another.
Listing 12-8.AttributeMapper Interface
public interface AttributeMapper {
void map(Object source, Object target, Map context);
}
Example
Let’s look again at the subflow state and attribute mappings from Listing 12-7:
<subflow-state id="enterShippingInformation" flow="shipping-flow">
<attribute-mapper>
<input-mapping name="purchase.requiresShipping" as="requiresShipping"/>
<output-maping name="shipping" as="purchase.shipping"/>
</attribute-mapper>
<transition on="end" to="placeOrder"/>
</subflow-state>
The <input-mapping>element instructs Spring Web Flow to map the value of the
requiresShippingproperty of the purchaseobject in theparent flow scopeto an attribute in
the subflow scope with the name requiresShipping.
The <output-mapping>element instructs Spring Web Flow to map the result of
the shippingsubflow output attributeto the shipping property on the purchaseobject in the
parent flow scope.
Figure 12-1 graphically represents this.
Figure 12-1.Graphical representation of mapping attributes to and from a subflow
Purchase Flow Shipping Flow
requires Shipping
shipping
purchase.requiresShipping
requiresShipping
requiresShipping
shipping
purchase.requiresShipping
purchase.shipping
342 CHAPTER 12 ■ADVANCED SPRING WEB FLOW