--- 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.
AFAIK, yes. Not sure what else it would be used for. > If so (and even if not), why? It moves initialization code from the mainline code and provides a uniform, deterministic way to run it across an application. As a counter-example, consider a multi-developer project where each developer initializes actions in a different way: some embed the code in an action's execute() method, some call an initialization method in execute(), some use an interceptor, ad nauseam. Preparable unifies the initialization mechanism. > 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. Don't forget that Preparable isn't just the prepare() method, it's also prepareXxxx() if you write actions with multiple methods. (Multiple methods per action class is a cultural decision, and is debated from time to time.) Consider also an action under unit test: it may not be desirable to call the Preparable methods during testing, instead initializing the action manually to allow testing of specific behaviors. > 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? "Should" implies a level of obligation I'm not comfortable with. I don't find the use of Preparable to be much of a productivity boost; the "mainline" code savings are minimal, and it depends on framework knowledge to understand why and how code using it works. I am ambivalent about its use, but comfortable with either viewpoint. Dave --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]