I'm signed up for the Struts 1.1 task entitled "XML --> ActionForm Code
Generator", and am working on such a tool at the moment. There has been a
fair amount of discussion on various types of validation recently, so I
wanted to throw this variant into the mix and see what people think.

Server-side validation in a Struts application typically happens in two
different phases. What might be referred to as "early" validation (usually
just syntactic validation) is done within the form bean (in
ActionForm.validate()), while "late" (more complex) validation is left to
the Action to handle.

The question, then, is how best to handle "early" validation in the case
where the form bean is being generated automatically rather than being
hand-coded. At this point, I see three alternatives, and this is where I'd
like to hear what people think.

1) Do nothing. If the developer wants to do early validation, s/he can
implement the validate() method by hand to do whatever is necessary.

2) Generate the validate() method based on validation rules specified in the
XML definition of the form bean (e.g. within struts-config). This would
generate a static (i.e. at bean-creation-time) specification of the
validation algorithm.

3) Generate a validate() method whose behaviour is defined by an external
specification (e.g. in XML). This could be along the lines of the Validator
implementation proposed by David Winterfeldt.

A combination of (2) and (3) might also make sense, where a basic validation
scheme might take care of existence rules (e.g. 'required') and type
definitions (e.g. 'must be an integer'), but where more sophisticated
validation (e.g. must match 'mm/dd/yy') would be left to an external
validator.

What do people think about this?

--
Martin Cooper
Tumbleweed Communications



Reply via email to