You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Victor Batista <vb...@present-technologies.com> on 2002/12/28 17:07:54 UTC

Call methods from different Actions

Hello!
	How can I access from one Action, say ActionA, one method which is under a
different Action (say ActionXpto). Can I create a new instance of
ActionXpto, and call the desired method from ActionA? Is it possible through
Struts to get one instance of ActionXpto?

	Thanks in advance,
		Victor Batista

	PS - I have one BaseAction which all Actions extend. Although I don't want
this method to be on the Base class.


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Call methods from different Actions

Posted by Taylor Cowan <t....@charter.net>.
Sure, you can create an instance of the action and call its methods.  That's
all struts does anyway.  I had used that technique once to provide a
"cleanup" or destructor method on my actions so that when you leave an
action you can clean up any temporary session values that aren't needed
later.

It sounds like you might benefit by refactoring the desired method in
"ActionXpto" into a regular java class, perhaps as a static method, then
you're just calling a regular method.  It's even better if the method
doesn't need req, res and other container items which will allow Junit
testing outside the container.

Taylor

----- Original Message -----
From: "Victor Batista" <vb...@present-technologies.com>
To: <st...@jakarta.apache.org>
Sent: Saturday, December 28, 2002 8:07 AM
Subject: Call methods from different Actions


> Hello!
> How can I access from one Action, say ActionA, one method which is under a
> different Action (say ActionXpto). Can I create a new instance of
> ActionXpto, and call the desired method from ActionA? Is it possible
through
> Struts to get one instance of ActionXpto?
>
> Thanks in advance,
> Victor Batista
>
> PS - I have one BaseAction which all Actions extend. Although I don't want
> this method to be on the Base class.
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>