With preparable, you can load the objects you need in prepare() method, and do whatever specific you want in the actual called method. In CRUD actions, it is very handy to use prepare and paramsPrepareParams to first load the stuff you want, and after prepare all the parameters are inserted automatically. You don't need to change or access the object states explixitly at all in many cases -- the second params interceptor in the stack does that for you.
On Wed, Apr 16, 2008 at 4:22 PM, Michael Gagnon < [EMAIL PROTECTED]> wrote: > I've been working with struts2 for about 2 months and so far I've been > using > the preparable interface to populate any data the resulting page wants to > display. I've used the execute method to do non-visible work and determine > a > result (which controls flow). > > > > I'm wondering if this is the intended pattern. If so (and even if not), > why? > The only intended benefit I see to using prepare at all is if you somehow > want to use one action in two different contexts - one which uses the > preparable interceptor and one which doesn't. If this was ever the case, > I'd > argue two different actions should exist. If there's some common > functionality needed it should be in a superclass and the subclasses > should > call into it in the execute method. So given the only appropriate scenario > I > can think of off the top of my head, its use looks like an anti-pattern to > me. > > > > > > I see prepare being used in the way I'm using it in many tutorials but I > haven't found any articles explaining any particular reason why. I'm > hoping > maybe somebody can shed some light on this. should I bother using prepare > at > all? Why? > >