struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ted Husted" <hus...@apache.org>
Subject Re: [Strust2] how does Interceptor work?
Date Wed, 27 Sep 2006 15:13:13 GMT
> Maybe there is a better way?

Have you looked at Prepare?

http://cwiki.apache.org/WW/prepare-interceptor.html

It's enabled by default, so if you want to be sure a method fires
before execute (or input, or cancel, or anything else), then just
implement preparable.

The MailReader application does this to setup a drop down list for the
input form.

public class Subscription extends MailreaderSupport
        implements Preparable {

    private Map types = null;
    public Map getTypes() {
        return types;
    }

    public void prepare() {

        Map m = new LinkedHashMap();
        m.put("imap", "IMAP Protocol");
        m.put("pop3", "POP3 Protocol");
        types = m;

        setHost(getSubscriptionHost());
    }

// ....

}

One thing you don't have to worry about doing before or after execute
is fussing with checkboxes. Struts 2 has automatic support for
stateful checkboxes, so there is no more mucking around with resetting
input, just because HTTP can't say "false" :)

-- HTH, Ted.
* http://www.husted.com/struts/




On 9/27/06, Labey Sébastien <slabey@sopragroup.com> wrote:
> Thanks for your help. I've read these pages and I better understand how it works. I've
to try this further now...
> You said I could post my Interceptor to the list, but for the moment it doesn't really
exist... It is only an idea to have an Interceptor that belongs to my default Interceptor
stack and that give acces to before() and after() methods in all Action whatever the method
that is called in the Action. So I could add some work to do before and/or after the execute()
method (or create() or update() or read()...) if needed without having to modify the Interceptors
discribed in the struts.xml for the specific action. All actions could extend these before()
and after() methods only if needed.
> One other solution would be to describe a "mother" Action class that would call before()
and/or after() methods of the Action class called during the execute() method... not sure
that it is very clear...
> Maybe there is a better way?
>
> -----Message d'origine-----
> De : David Evans [mailto:dsevans@berndtgroup.net]
> Envoyé : mardi 26 septembre 2006 18:42
> À : Struts Users Mailing List
> Objet : Re: [Strust2] how does Interceptor work?
>
>
> Hello,
>
> These webwork and xwork doc pages may help:
> http://wiki.opensymphony.com/display/XW/Interceptors
> http://www.opensymphony.com/webwork/api/com/opensymphony/xwork/ActionInvocation.html
> http://www.opensymphony.com/webwork/api/com/opensymphony/xwork/ActionProxy.html
>
> Passed in to your interceptor's intercept method is an ActionInvocation.
> This object has a getProxy() method, which returns an ActionProxy.
> The ActionProxy has a getMethod() method, which will return the method
> name as a String. So you'll need to call those methods and then use
> reflection to call your beforeXXX and afterXXX methods.
>
> In your intercept method the invocation.invoke() line is what continues
> down the chain of interceptors and finally to the Action's method.
> Anything you do before the invocation.invoke() is before the action
> execution, anything after invocation.invoke is after the action
> execution. It is also after the result execution, so for your case it
> seems you'd have to setup the PreResultListener, and put the ActionProxy
> method lookup and reflective call bit in there as well.
>
> If you post your Interceptor to the list, that might help also.
>
> Dave
>
>
>
> On Tue, 2006-09-26 at 12:11 +0200, Labey Sébastien wrote:
> > Hi, I'm new to Struts2 and i don't really understand how does Interceptor technique
work.
> > I have made my own interceptor that implements Interceptor interface. I place it
in struts.xml with my action. It's OK, before invoking my action, i go through my interceptor
in the intercept() method.
> > But do all interceptor classes go only through intercept() method or is there a
solution to go through another method name? My need is to go through a beforeXXX() method
depending on the name of the méthod described in struts.xml for my current navigation.
> >
> > My second question is how to go through an interceptor after the action has been
executed but before "forwarding" to jsp? I read in documentation that my interceptor has to
implements PreResultListener interface, so i made it, but nothing appens. I dont go through
the beforeResult() method, neither the intercept() method... Is it possible to have only one
interceptor for both the beforeXXX() and the afterXXX() methods?
> >
> > All your helps would be great. Thanks in advance
> >
> > Sebastien
> >
> >
> > Sébastien LABEY
> >
> > Division Immobilier
> > R&D IKOS
> >
> > 04.72.18.47.07
> >  <mailto:slabey@sopragroup.com> slabey@sopragroup.com
> > 20, chemin du Randin - B1 - 69130 Ecully
> > P Avant d'imprimer, ayez une pensée pour notre environnement

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


Mime
View raw message