You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Rob <bs...@insightoutsight.com.au> on 2003/06/14 06:33:46 UTC

executing statements on subsets of actions without code duplication

I have a set of statements I would like executed every time
an action is executed.  I would also like to only have to
code these set of statements once and have them transparently
executed for all actions (except for a small subset).

Is there a facility in struts for doing this?  Is there an
example somewhere perhaps in the example application?
(I couldn't see one)

Thanks


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


Re: executing statements on subsets of actions without code duplication

Posted by Rob Leland <rl...@apache.org>.
Rob wrote:

>
> Rob Leland wrote:
>
>> Rob wrote:
>>
>>> I have a set of statements I would like executed every time
>>> an action is executed.  I would also like to only have to
>>> code these set of statements once and have them transparently
>>> executed for all actions (except for a small subset). 
>>
>>
>>
>> When we were using a Servlet 2.2 container we derived a class
>> from Action named SecureAction, which checked that the user was 
>> logged in.
>>
> Can you explain how this was done in a little more detail, particularly
> what methods were used, where they were used etc..?  I have the current
> arrangement where I extend Action with a BaseAction, which implements
> my common method (the one to be called always) and then from subclasses
> of BaseAction.execute() I call the common method. 


Find out what method in Action calls the execute() method, which is empty.
I forget. Override that method in BaseAction, then place a call to your
common method in that method. That way no Action can be called unless
your common method says it can.

-Rob

>
>
> It is this having to manually call the common method I would like to
> eliminate and just have it transparently occur higher in the
> hierarchy.
>
> As for your suggestion of using filters could you direct me to more
> information regarding that method I'm interested in exploring it.
>
> Thanks
>
>> Then all the applications Actions would be SecureAction Children.
>>
>> If struts had events then the event could be hooked instead, this is 
>> easy enough to do.
>>
>>
>> Under Servlet 2.3 filters could be used.
>>
>> -Rob
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>



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


Re: executing statements on subsets of actions without code duplication

Posted by Rob <bs...@insightoutsight.com.au>.
Rob Leland wrote:
> Rob wrote:
> 
>> I have a set of statements I would like executed every time
>> an action is executed.  I would also like to only have to
>> code these set of statements once and have them transparently
>> executed for all actions (except for a small subset). 
> 
> 
> When we were using a Servlet 2.2 container we derived a class
> from Action named SecureAction, which checked that the user was logged in.
> 
Can you explain how this was done in a little more detail, particularly
what methods were used, where they were used etc..?  I have the current
arrangement where I extend Action with a BaseAction, which implements
my common method (the one to be called always) and then from subclasses
of BaseAction.execute() I call the common method.

It is this having to manually call the common method I would like to
eliminate and just have it transparently occur higher in the
hierarchy.

As for your suggestion of using filters could you direct me to more
information regarding that method I'm interested in exploring it.

Thanks

> Then all the applications Actions would be SecureAction Children.
> 
> If struts had events then the event could be hooked instead, this is 
> easy enough to do.
> 
> 
> Under Servlet 2.3 filters could be used.
> 
> -Rob
> 


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


Re: executing statements on subsets of actions without code duplication

Posted by Rob Leland <rl...@apache.org>.
Rob wrote:

> I have a set of statements I would like executed every time
> an action is executed.  I would also like to only have to
> code these set of statements once and have them transparently
> executed for all actions (except for a small subset). 

When we were using a Servlet 2.2 container we derived a class
from Action named SecureAction, which checked that the user was logged in.

Then all the applications Actions would be SecureAction Children.

If struts had events then the event could be hooked instead, this is 
easy enough to do.


Under Servlet 2.3 filters could be used.

-Rob

>
>
> Is there a facility in struts for doing this?  Is there an
> example somewhere perhaps in the example application?
> (I couldn't see one)
>
> Thanks
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>



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