The ActionForm is considered to be a container for
holding and preserving the information the user has
entered. So you don't want to reject any data at this
level because if the validation fails you want to
return exactly what the user has entered. So most
people use String getter/setters in the ActionForm
(checkboxes could use boolean). There was just a
large thread discussing this if you want to read
different peoples responses.
http://www.mail-archive.com/[email protected]/msg01962.html
Here is one of my responses:
I don't think there would be anything wrong with your
idea, but I think it is a little more flexible keeping
the validation separate from the ActionForm. I
started working on a validation framework, but I put
the info in an xml file. I would rather change a
value in an xml file than having to recompile my code.
* It makes the validation rules more accessible to
less technical people. One day the XML might tie into
a JSP editing tool to provide easy access and editing
of the validation rules.
* I think it makes it easier to generate JavaScript
that has the same information you pass into the java
validation method.
* It let's you decouple the actual code that performs
a validation from the validation. You can just say a
field is required and if you redefine what
class/method performs the required validation you
won't need to change anything else. (not that you
couldn't do this with an interface you've created too)
* When the exception/validation happens in the setter,
you can't do things that depend on other fields. Like
this field is required only if another field is filled
in.
These are a couple of thoughts off the top of my head.
Here is a link to what I've done so far.
http://home.earthlink.net/~dwinterfeldt
Also the current system isn't able to handle an
exception being thrown during the auto-population of
the ActionForm from the request.
David
--- Jonathan Fuerth <[EMAIL PROTECTED]> wrote:
> Hi. I'm new to struts (I've been working on my
> first struts webapp
> for the past few days), but I have a design question
> to ask:
>
> Why is there a separate validation call to an
> ActionForm? Isn't the
> normal JavaBeans PropertyVetoException model cleaner
> and easier to
> maintain?
>
> I may well be missing the point. Is there some
> design pattern in the
> validate() method which doesn't make the programmer
> separate
> validation from the property setter method, which is
> also compatible
> with PropertyVetoException?
>
> Thanks!
__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/