struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject RE: Struts2 Validation w/ModelDriven
Date Thu, 19 May 2011 19:55:02 GMT
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);
      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


-----Original Message-----
From: Eric Lentz [] 
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
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:
For additional commands, e-mail:

View raw message