Simplify your AppFuse Managers
I figured out a way to remove any ActionForm references from my Managers yesterday. It was pretty simple, but I thought others might benefit from this knowledge. Basically, you just need to add a couple methods to your BaseManager.java file. Here is the latest one from CVS HEAD. Then you can pretty much eliminate any *Form references in your Manager by using the convert(Object) method. This method will convert POJOs <-> Forms and vise versa. You will likely have to do some tweaks on the package names if you're using anything < v1.4. Looking at this diff of the UserManager before and after this change will show you what's changed.
I started this task thinking I could remove the need for Forms in my classpath when compiling the service layer. However, I soon discovered that my Tests have Forms all over the place - since they replicate what my Actions will pass in. Oh well, at least my code is a bit cleaner now.
Of course, this code will become even simpler when I start using an MVC Framework that allows my POJOs to be my data handlers on the UI. These frameworks make me question if I even need Managers. Then again, it's nice to unit test what your DAOs are returning/receiving from the web layer.
Posted by Carl Fyffe on February 20, 2004 at 04:28 AM MST #
1. Override ActionServlet so that the execute method takes an Object instead of an ActionForm.
2. Allow POJOs to be used in Struts Actions and use the Validator and possibly AOP or Interceptors to validate POJOs.
3. Continue to use the Validator's client-side validation feature.
4. Figure out a way to accomplish the above, but still allow for displaying any invalid input in form elements.
If the Validator could validate POJOs as easily as it can ActionForms, it could be used in any MVC framework - powerful stuff!
Posted by Matt Raible on February 24, 2004 at 05:31 AM MST #