struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Joe Germuska" <>
Subject Re: Creating an instance of an action a class
Date Fri, 26 Jan 2007 22:01:18 GMT
On 1/26/07, Christopher Schultz <> wrote:
> Hash: SHA1
> Frank,
> Frank W. Zammetti wrote:
> > There is no special status for an Action beyond that though, no
> > values set on it by Struts, that sort of thing.  Just instantiate and
> > execute as you would any other class.

I feel obliged to point out, though, that if you have a lot of behavior in
your actions such that this is an initially attractive solution, you may
want to reassess your architecture and possibly refactor.  Should you set up
an inheritance tree of actions?  Should you factor some of that logic out
into classes which aren't even dependent upon Struts?  I always aim to keep
my actions light weight, mostly responsible for managing the translation
between HTTP request parameters (fundamentally Strings) and the application
object model (either other primitives converted from the strings, or model
objects looked up based on the parameter values, etc), and session

This helps write code that is more easily unit tested, and also plays much
better with the overall "ecosystem" we find ourselves developing in now that
we use Spring and Hibernate extensively.  Things like proper transaction
management in Spring/Hibernate are pretty much predicated on limiting the
behavior in your action and putting more of it behind one "model" method
which can be marked with transaction semantics.  It also lends itself better
to mixed mode applications where you want the same basic code to handle both
online (web) processes as well as offline (batch file processing, etc).

Just something to keep in mind...


Joe Germuska *

"The truth is that we learned from João forever to be out of tune."
-- Caetano Veloso

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message