spring-webflow
spring-webflow copied to clipboard
Enhance bean invoking action to provide built-in exception handling support [SWF-321]
nebhale opened SWF-321 and commented
Currently, if an exception is thrown as a result of invoking a bean invoking action, the exception propagates back to the flow and the flow is expected to respond to the exception using either an exception handler typically or by declaring an on exception transition. This works fine but generally requires transition to a intermediate state to map the exception onto a set of error validation methods. Either that or the view must translate the exception to error messages. It would be nice if the bean invoking action itself could handle the exception, record suitable validation error messages and return a result that could be handled by the flow. This would make exception handling simpler from the flow definition point of view and build in alert creation.
For example before this feature you'd do this:
<action-state id="changeBeneficiaryAllocations"> <bean-action bean="accountManager" method="updateBeneficiaryAllocationPercentages"> <method-arguments> <argument expression="flowScope.accountId" /> <argument expression="requestScope.allocationPercentages" /> </method-arguments> </bean-action> <transition on="success" to="editBeneficiaries" /> <transition on-exception="accounts.InvalidAllocationException" to="generateErrorMessages"/> </action-state>
after you'd do this:
<action-state id="changeBeneficiaryAllocations"> <bean-action bean="accountManager" method="updateBeneficiaryAllocationPercentages"> <method-arguments> <argument expression="flowScope.accountId" /> <argument expression="requestScope.allocationPercentages" /> </method-arguments> </bean-action> <transition on="success" to="editBeneficiaries" /> <!-- Error message generated automatically --> <transition on="invalidAllocation" to="enterNewBeneficiaryAllocations"/> </action-state>
Affects: 1.0.3
Issue Links:
- #159 Introduce a successor to FormAction for data binding and validation ("depends on")
1 votes, 2 watchers
Erwin Vervaet commented
I'm not sure about this. Using an on-exception transition seems to be pretty elegant and most people are happy with it.
Keith Donald commented
Using transition on-exception is no doubt elegant and powerful. However, it's arguably redundant when all you want to do is map the exception to an error message and logical error outcome, then redisplay a view. Having to implement this same control flow logic over and over again for every call into the service-layer that throws a checked exception results in duplication. It seems we have a natural opportunity to encapsulate some of this inside the bean invoking action itself to simplify exception handling for users (via convention over repetitive configuration).
Keith Donald commented
This issue depends on enhancements to the RequestContext to expose an API for recording validation error messages.