An Action is no different from any other class, you can do this without
any ill effects.  Whether it's architecturally a good idea is a whole
other question, but from a technical standpoint, no problem.  I've done
this numerous times in the past, it works just fine.

Remember though that the method may well return an ActionForward, so you
need to either ignore it or return it from the calling execute() method so
Struts still does its thing after the fact.

Christopher may have been referring to the fact that Struts creates
essentially a pool of Actions, one instance of each, and a given request
always executes that instance.  This was done early on in Struts' life
because the cost of object instantiation used to be a lot greater than it
is today, so better to avoid it entirely.  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.

The architectural problem I alluded to is that if you are trying to do
this, you probably in fact have some code you should pull out into a
common "helper" class instead.  Chances are that's what your trying to do,
in which case instantiating and executing an Action isn't really the right
answer from an architecture point of view.

Frank


-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM/Yahoo: fzammetti
MSN: [EMAIL PROTECTED]
Author of "Practical Ajax Projects With Java Technology"
 (2006, Apress, ISBN 1-59059-695-1)
Java Web Parts - http://javawebparts.sourceforge.net
 Supplying the wheel, so you don't have to reinvent it!

On Fri, January 26, 2007 2:02 pm, Christopher Schultz wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Chamal,
>
> chamal desilva wrote:
>> Is it safe to create an instance of a action class in
>> another action class and use.
>>
>>    public ActionForward execute (....)
>>    {
>>          OtherAction oact = new OtherAction();
>>          oact.execute(....);
>>    }
>
> Although that /might/ work, you probably don't want to do that. I would
> imagine that Struts does a lot of configuration of each Action before
> any requests are processed using it.
>
> You might want to think about making NewAction extend OtherAction and
> use a common superclass method to do some of your work for you. That
> strikes me as a cleaner design, anyway.
>
> - -chris
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFFulBV9CaO5/Lv0PARAiGCAJ4xi3NRSUuEPlh1EEkpDuWvicCd8gCeN8dI
> N6cZUr6AX6xW1DtllklPDRg=
> =zkV6
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


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

Reply via email to