<transition on="checkPermissions.error" to="accessDenied.view"/>
<transition on="checkPermissions.success" to="nextAction"/>
</action-state>
■NoteBoth lockActionand securityAction were trivial adapters between Spring Web Flow and the
business tier and hence are not shown. In the “POJO Actions” section later in this chapter you will see how
to do away with such objects.
Although this worked, it was not ideal; the business rule was only enforced in the flow
definition. If the business rule was changed (e.g., they only had to have exclusive access) then
the web flow definition would have to change, even though the affected logic has nothing to
do with presentational or navigational logic.
Many enterprise applications have multiple entry points into the system, including not
only the XHTML interface, but also web services, batch updates, and even rich clients. When
business logic resides only in web flow artifacts, all other systems either lack that logic or need
to reimplement it. For this reason, keep the business logic of the system out of the web flow
layer and inside the business (or service) layer and domain model.
■Tip Asking the question “what needs to change if I changex?” is a good way of determining whether
xbelongs or not. If changing xrequires changing multiple layers or a seemingly irrelevant layer (as in this
case), then there is something wrong with the application design. In this case, a change to the business logic
resulted in a change to the flow definition, indicating the flow definition is not the right place for this logic.
So what is the solution? Simple: Move the business rule out of the web flow. Does this pre-
vent the web flow from referencing the business rule? Of course not, it simply means that the
web flow does not implementthe business rule. Refactoring might lead to something like
Listing 12-2.
Listing 12-2.Spring Web Flow Fragment Referencing Business Rules
<action-state id="checkRights ">
<action bean="checkRightsAction"/>
<transition on="error" to="rightsViolation.view"/>
<transition on="success" to="nextAction"/>
</action-state>
The flow now drives the execution of the business rule, but does not defineit. When
implementing Spring Web Flow, be sure to avoid inadvertently coding business logic inside of
your flow.
336 CHAPTER 12 ■ADVANCED SPRING WEB FLOW