The answer to this is in fact the difference between ActionForm and DynaActionForm.
In Struts, everybody knows the ActionForm class (so I'm not gonna talk about it). But not everybody knows (or understands the purpose of - me included) the DynaActionForm.
The idea behind DynaActionForms is that instead of creating a form class for each HTML form, you instead configure one (you declare their properties, types and defaults in the struts-config.xml file). It was supposed to be "Dyna"mic you know... but turned out to be some thing that nobody understood or used and presented some major disadvantages:
- they act sort of like a Map so it has the same problems of maps, like retrieving data from it, you know, as an Object which you then have to cast. So you have casts everywhere;
- compiler no longer notifies you when you screw something up like a name of a property for example, so compile errors turn into runtime errors;
- the things are not really dynamic since you still have to restart the server after you "reconfigured" the properties in the struts-config.xml file (or else modifications won't be picked up);
- code completion does not work on DynaActionForms, type safety sucks (we are not taking generics here) and there are other nuisances that I can't remember right now.
Well... the idea is that, from a Struts point of view, you have two main types of forms to deal with: ActionForm and DynaActionForm (even if the DynaActionForm is in fact a subclass of ActionForm).
But you also have the validator plugin where you place your validation rules in an external file and make them pick up by your action forms. You hook up the validator plugin by using a child of ActionForm: the ValidatorForm. And since you have two types of forms you must hook up the validator plugin for the DynaActionForms also: enter the DynaValidatorForm.
In conclusion, the ValidatorForm and DynaValidatorForm are the same thing but applied to different "beasts".
No comments:
Post a Comment