struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hubert Rabago <hrab...@gmail.com>
Subject Re: Wouldn't validation be better performed by Actions rather than ActionForms?
Date Fri, 18 Mar 2005 17:27:11 GMT
You raise a lot of points, and I admit I won't be able to respond to
all of them in one email (due mostly to time constraints).  Besides,
there are others who could respond, so I'll leave some out for them.
:)

There are/can be different levels of validation.  Some validation you
perform before others.  For example, an HR entry screen might contain
a field for salary.  You would validate that the field contains a
valid String that can be converted into a double, and you'd also make
sure it doesn't exceed certain bounds (like, say, USD 10,000,000 for a
junior programmer).  If the field doesn't contain a valid double,
there's no sense checking its value boundaries.  The field itself is
not syntactically valid.  This level of validation is what's most
often assigned to the ActionForm.  Much of these can be
automated/declared and oftentimes the Action doesn't even need to
participate.  Hence, we let the ActionForm carry out this part, and if
it fails at this level, we don't even bother calling the Action.

Hubert

On Fri, 18 Mar 2005 17:17:39 +0000, Lawrie Gallardo
<lawriegallardo@hotmail.com> wrote:
> I'm still relatively new to Struts, but I can't help but feel that
> validation would be better performed by Action classes rather than
> ActionForm classes.
> 
> It seems to me that, ideally, you want
> 1. Validation,
> 2. Transformations (ie convert separate day, month and year HTML fields to
> Java Date object), and
> 3. Mapping of ActionForm fields (/HTML parameters) to Domain POJOs / DTOs
> to all be configured in the same config file (to minimise duplication) and
> to be implemented in the same class rather than scattered between multiple
> config files and classes.
> 
> Now, if my understanding is correct:
> 1. There is always a one-to-one mapping between an ActionForm and an
> ActionMapping,
> 2. Struts best practice is to have each Action class handle all possible
> operations for the HTML request it deals with using DispatchLookupAction or
> something similar,
> 3. Almost noone creates ActionForms manually any more - they use
> DynaActionForm (or validating variations of this). And for those who do
> still create ActionForms manually, they don't offer anything in the way of
> reuse, and are basically throw-away classes.
> 
> Now if this is the case, would it not be better to have the ActionForm as
> basically a dum data holder and have the validation method in the Action
> classes instead? The strus-config.xml file could contain all the required
> declarative validation, transformation and mapping info, and the Action
> class could contain any validation, transformation, and mapping operations
> that were too complicated to be set up declaratively.
> 
> Is it just down to design decisions made in early versions of Struts and
> backward compatibility that things are the way they are? Or are there good
> arguments for having the validation method in ActionForm? Am I missing
> something here?
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message