Strut like WebWork (sort of). As you may have gleaned from an earlier post, I'm stuck in Struts for the moment. There are a few design aspects of Struts that really rub me the wrong way. For example:
1. Separate actions and forms. Since when do we separate data and logic?
2. Action instances shared between multiple requests.
3. The Servlet API classes are in your face.
4. No interceptor chains.
I was talking with Gavin King at TSS Symposium, and he mentioned that in his own Struts use, he had moved the logic from the action to the form and reused the same action type for all of his action mappings. I took a couple hours and implemented Gavin's suggestion as well as support for interceptor chains. My coworkers have been very happy with the results. We implement half as many classes, the action implementations are much cleaner (less casting, form.getXxx() calls, etc.), and unit tests are a snap. I've been calling the framework Struts Delegate (because the actions delegate responsibility to the forms).
Here are the fully unit tested and javadocumented deliverables:
In a nutshell, you have DelegateAction which delegates execution to DelegateForm. You can define interceptor chains by sub classing DelegateAction and overriding the interceptor chain factory method (one possible implementation could use an XML file to configure chains). I've provided one specialization of DelegateForm, DispatchForm which serves the same purpose as DispatchAction in the Struts framework (invoking the method specified in the action mapping parameter instead of execute()). There are examples in the distribution which more clearly illustrate how everything fits together.
The Struts Action Invocation Framework (SAIF) aims to accomplish the same task, and it supports IoC (which mine does not), however it falls short in a couple key areas:
You can easily plug your favorite IoC implementation into Struts Delegate using an interceptor. Hopefully, I'll be able to toe WebWork through the corporate door soon, but in the mean time, happy Strutting to those of you who find yourselves in the same situation.
View the blog: Bob Lee: Strut like WebWork (sort of)