There's nothing wrong with using @After rather than @Before.

The fact that you are asking the question hints at the possibility that you
don't really have a good idea of when the lifecycle events occur, which
could be a problem.  If you're going to schedule an event before or after
some other event, you should probably know what occurs at each step.

Read this, if you haven't already:
http://stripesframework.org/display/stripes/Lifecycles+Etc.

If it's still not clear when to schedule your event, the stripes source code
is excellent, and highly readable.  My suggestion would be to have a look at
the DispatchHelper class.

So given that you really do need to understand the lifecycle to effectively
use the @Before and @After annotations, I would suggest using @Before when
you need to initialize data for an operation.  Use @After when you need to
do some clean up following an operation.

There are, of course, exceptions.

On Tue, Sep 22, 2009 at 10:28 PM, Rusty Wright <[email protected]>wrote:

> As per the Stripes' Best Practices page I added a rehydrate method
> annotated with @Before.
>
> 1) I found using @Before with BindingAndValidation confusing so I changed
> it to @After with HandlerResolution and that seems to work.  Is that ok?
>
> 2) Instead of using this @Before/@After method I had been setting up the
> object in the @DefaultHanlder and that seemed to work.  What are the pros
> and cons of each way of doing it?
>
> Here are the relevant methods:
>
>    /**
>     */
>    @After(stages = LifecycleStage.HandlerResolution)
>    public void rehydrate() {
>        this.log.debug("called");
>
>        this.desiredDate = this.desiredDateFactory.create();
>
>        this.dateFormBacker = new DateFormBacker();
>    }
>
>    /**
>     * @return Resolution
>     */
>    @DefaultHandler
>    public Resolution view() {
>        this.log.debug("desiredDate: " + this.desiredDate);
>
>        return (new ForwardResolution("/WEB-INF/jsp/start.jsp"));
>    }
>
>    /**
>     * @return Resolution
>     */
>    public Resolution submit() {
>        this.log.debug("desiredDate: " + this.desiredDate);
>
>        final int id = this.dateService.saveDesiredDate(this.desiredDate);
>
>        getContext().setDesiredDateId(Integer.valueOf(id));
>
>        return (new RedirectResolution("/list.zug"));
>    }
>
> Thanks
>
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
> http://p.sf.net/sfu/devconf
> _______________________________________________
> Stripes-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/stripes-users
>
------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to