(I almost missed the questions you had inline, thinking that the
message you had at the top was all there was.)

> Could you give any example reasons why (/ situations when) you would use 
multiple individual Action classes in favour of an Action with dispatching 
functionality? I am still learning Struts so my assumptions are just based 
on the books and articles I've read (which frequently tell you what the 
various options are, but not why you would use one in preference to 
another...).

I like to keep my actions simple and focused.  I only switch to a
multi-function Action object when it's apparent that there's
functionality I want shared between actions that I don't want to
copy/paste but I don't feel like putting it in a shared class either.

Also, when I have operations that are almost pure CRUD, I usually
combine them into a dispatch-type action so I can deal with all of
them in one place.  In these situations, I usually write the whole
action, with all its CRUD methods, in one go.  This makes me feel
that, even though it's a dispatch-flavor action, it's still a simple
and focused Action class.

I don't necessarily advocate these as best practices; I do them
because they were what worked for me at the time given the situation I
faced then.  I guess that means you don't get much out of me, either. 
:)


> Again, I'd be most grateful if you could provide me with some real-world 
examples of when you might want to manually create an ActionForm...

This is when I need to do validation that's too complicated for
Validator, or I need to do more than
BeanUtils.copyProperties/FormUtils.set/getFormValues()  to map between
the form I show and my business object.  My favorite example is when I
had a form which had a list of maps of values.  I chose the regular
ActionForm subclass because I felt it was easier for both me and my
teammates to follow along with what was going on, thereby making it
easier to maintain.  If I had a search page with just a search string
and simple options, I'd certainly use dynamic forms, which in this
case would be easier to maintain.


hth,
Hubert


On Fri, 18 Mar 2005 20:24:19 +0000, Lawrie Gallardo
<[EMAIL PROTECTED]> wrote:
> Thanks Hubert - you have certainly given me a few things to think about...
> 
> >From: Hubert Rabago <[EMAIL PROTECTED]>
> >Reply-To: Hubert Rabago <[EMAIL PROTECTED]>
> >To: Struts Users Mailing List <user@struts.apache.org>
> >Subject: Re: Wouldn't validation be better performed by Actions rather than
> >ActionForms?
> >Date: Fri, 18 Mar 2005 11:39:33 -0600
> >
> >Inline.
> >
> >On Fri, 18 Mar 2005 17:17:39 +0000, Lawrie Gallardo
> ><[EMAIL PROTECTED]> 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.
> > >
> >
> >Hmm, you just described one use case for FormDef when coupled with its
> >Validator integration.  :)
> >https://formdef.dev.java.net
> >http://www.rabago.net/struts/formdef/manual.htm#combinedconfig
> >
> >
> > > Now, if my understanding is correct:
> > > 1. There is always a one-to-one mapping between an ActionForm and an
> > > ActionMapping,
> >
> >An action form holds the request parameters that accompany a request.
> >The most common use case is a form being submitted.  You submit each
> ><form> to one URL - that's why there's a one-to-one mapping.
> >
> > > 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,
> >
> >That certainly is one practice.  Personally I don't use that.  I
> >mostly use my own Action subclasses, or if I want dispatch
> >functionality, I used to use MappingDispatchAction.  Now I use the
> >ActionDispatcher class in
> >http://issues.apache.org/bugzilla/show_bug.cgi?id=31270 .
> >
> 
> Could you give any example reasons why (/ situations when) you would use
> multiple individual Action classes in favour of an Action with dispatching
> functionality? I am still learning Struts so my assumptions are just based
> on the books and articles I've read (which frequently tell you what the
> various options are, but not why you would use one in preference to
> another...).
> 
> > > 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.
> >
> >My own rule has been, if the requirements can be fulfilled by a dyna
> >form, then that's what I use.  Otherwise, I use a manually created
> >ActionForm.  Whenever I have a manually created ActionForm, believe
> >me, they're certainly not throw-away.
> >
> 
> Again, I'd be most grateful if you could provide me with some real-world
> examples of when you might want to manually create an ActionForm...
> 
> >Hubert
> >

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to