开发者

Difference between ValidatorForm and DynaValidatorForm

开发者 https://www.devze.com 2023-01-29 08:13 出处:网络
What is the difference between V开发者_运维知识库alidatorForm and DynaValidatorForm ? What is the difference between ValidatorForm and DynaValidatorForm?

What is the difference between V开发者_运维知识库alidatorForm and DynaValidatorForm ?


What is the difference between ValidatorForm and DynaValidatorForm?

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".

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号