That should work fine until someonw switches you to the PrepareParamsPrepare
stack and prepere() gets called twice anyway. ;)
  (*Chris*)
On May 19, 2011 12:55 PM, "CRANFORD, CHRIS" <chris.cranf...@setech.com>
wrote:
> Eric -
>
> The framework will call getModel() multiple times before your validate()
> and execute() methods are invoked; and so by adding the create/lookup
> logic to getModel(); you would then have to wrap that block of code
> around a null check so that subsequent calls to getModel() would just
> return the model reference and not worry about creating or looking up
> the model object. (see below)
>
> public MyModelObject getModel() {
> if(model == null) {
> if(id == null)
> model = service.create(itemNumber,vendorNumber,quantity);
> else
> model = service.lookupById(id);
> }
> return model;
> }
>
> To me this is a performance issue because a null check is being
> performed for each getModel() invocation. And since my model should
> only be instantiated once; it's appropriate to put this in a method that
> is invoked only once per action request; which is the prepare() method.
>
> Personally I prefer to keep my design simple and clear and thus if any
> retrieval of data is done inside my actions it is either in the
> prepare() method or in the actual execute() or entry point method call
> being invoked in the action. Any getXXXX() methods are there simply to
> return the instance of a property member that has been initialized in
> either prepare() or the execute() or entry point method calls
> themselves.
>
> -Chris
>
> -----Original Message-----
> From: Eric Lentz [mailto:eric.le...@sherwin.com]
> Sent: Thursday, May 19, 2011 1:22 PM
> To: Struts Users Mailing List
> Subject: RE: Struts2 Validation w/ModelDriven
>
> I'm curious. If you are using ModelDriven, then why do you load your
> model
> in prepare()? Why not in getModel? I don't think behavior will be any
> different though since that interceptor is on the same side of the stack
>
> as prepare.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
>

Reply via email to