Raible's Wiki
Raible Designs AppFuseHomepage- Korean - Chinese - Italian - Japanese QuickStart Guide User Guide Tutorials Other ApplicationsStruts ResumeSecurity Example Struts Menu
Set your name in
UserPreferences
Referenced by
JSPWiki v2.2.33
Hide Menu |
Should XDoclet Generate Struts ActionForms?In AppFuse, you may notice that the ActionForms are autogenerated from the model's entity beans using @struts XDoclet tags. After trying every which way to wrap my application design around this approach, it finally became obvious to me that this is one case XDoclet over steps it's bounds. Read on to find out why... As tempting, beautiful and quick it may seem, I truly believe that generating ActionForms dynamically with XDoclet from custom tags in the model's entity beans is just not the right way to go. I believe that the relationship between these entity beans and the ActionForms is a forced association, one that you would like to believe so badly that you will convince yourself there is a direct tie when really there is little similarity at all. Entities have virtually the same fields as ActionForms in many cases, but the exceptions are enough to prove they should not be parallel (and even Ted Husted thinks so). ActionForms should be flexible to suit the view, not necessarily to suit the model. In fact, it is only your manager class (business delegate) that should care how you designed your ActionForms, so that even the DAO cares only about the entity design. Here are several reasons why XDoclet should NOT be used to make ActionForms from entity beans:
...and all for what? To generate something that eclipse can make in 10 seconds! Anyway, while it might suck, typing out an ActionForm isn't quite that hard and I think using xdoclet to generate them is just an indirection. You are most likely going to have to extend that generic ActionForm that xdoclet creates to provide extra methods anyway. For example, date handling needs a special object, nested forms need to have nested ActionForm objects and then there are collections. xdoclet just doesn't cut it here once you get into more complex apps (think event scheduler). I beat my head against the wall for hours until I just let go of ejbdoclet and then it all become very lucid. Your ActionForm is a very important view proxy to your entity beans, so don't try to get away with auto-generating it. That is my $0.02 and it is hard to convince me otherwise at this point because of how much easier it has already been to work with struts forms, xdoclet and my persistence data by abandoning xdoclet. Plus, now my entity beans don't have struts tags in them, a very important separation of model and view. Oh, and if I move a field to a different table/entity bean, I don't have to go redesign my form necessrily, though I do have to modify my Manager, but that is okay, because both are part of the business, not the view. The view is still safe. While I am dying for someone to see the light, I can live with enjoying it alone for a while. Remember, you don't want to overdo things, and this is backing away from xdoclet where it is prudent to do so.
|