@Deprecated public abstract class BaseCommandController extends AbstractController
Controller implementation which creates an object (the command object) on receipt of a request and attempts to populate this object with request parameters.
This controller is the base for all controllers wishing to populate
JavaBeans based on request parameters, validate the content of such
JavaBeans using Validators
and use custom editors (in the form of
PropertyEditors
) to transform
objects into strings and vice versa, for example. Three notions are mentioned here:
Command class:
An instance of the command class will be created for each request and populated
with request parameters. A command class can basically be any Java class; the only
requirement is a no-arg constructor. The command class should preferably be a
JavaBean in order to be able to populate bean properties with request parameters.
Populating using request parameters and PropertyEditors:
Upon receiving a request, any BaseCommandController will attempt to fill the
command object using the request parameters. This is done using the typical
and well-known JavaBeans property notation. When a request parameter named
'firstName'
exists, the framework will attempt to call
setFirstName([value])
passing the value of the parameter. Nested properties
are of course supported. For instance a parameter named 'address.city'
will result in a getAddress().setCity([value])
call on the
command class.
It's important to realise that you are not limited to String arguments in
your JavaBeans. Using the PropertyEditor-notion as supplied by the
java.beans package, you will be able to transform Strings to Objects and
the other way around. For instance setLocale(Locale loc)
is
perfectly possible for a request parameter named locale
having
a value of en
, as long as you register the appropriate
PropertyEditor in the Controller (see initBinder()
for more information on that matter.
Validators:
After the controller has successfully populated the command object with
parameters from the request, it will use any configured validators to
validate the object. Validation results will be put in a
Errors
object which can be
used in a View to render any input problems.
Workflow
(and that defined by superclass):
Since this class is an abstract base class for more specific implementation,
it does not override the handleRequestInternal() method and also has no
actual workflow. Implementing classes like
AbstractFormController
,
AbstractcommandController
,
SimpleFormController
and
AbstractWizardFormController
provide actual functionality and workflow.
More information on workflow performed by superclasses can be found
here.
Exposed configuration properties
(and those defined by superclass):
name | default | description |
commandName | command | the name to use when binding the instantiated command class to the request |
commandClass | null | the class to use upon receiving a request and which to fill using the request parameters. What object is used and whether or not it should be created is defined by extending classes and their configuration properties and methods. |
validators | null | Array of Validator beans. The validator will be called at appropriate places in the workflow of subclasses (have a look at those for more info) to validate the command object. |
validator | null | Short-form property for setting only one Validator bean (usually passed in using a <ref bean="beanId"/> property. |
validateOnBinding | true | Indicates whether or not to validate the command object after the object has been populated with request parameters. |
Modifier and Type | Field and Description |
---|---|
private BindingErrorProcessor |
bindingErrorProcessor
Deprecated.
|
private java.lang.Class |
commandClass
Deprecated.
|
private java.lang.String |
commandName
Deprecated.
|
static java.lang.String |
DEFAULT_COMMAND_NAME
Deprecated.
Default command name used for binding command objects: "command"
|
private MessageCodesResolver |
messageCodesResolver
Deprecated.
|
private PropertyEditorRegistrar[] |
propertyEditorRegistrars
Deprecated.
|
private boolean |
validateOnBinding
Deprecated.
|
private Validator[] |
validators
Deprecated.
|
private WebBindingInitializer |
webBindingInitializer
Deprecated.
|
METHOD_GET, METHOD_HEAD, METHOD_POST
logger
Constructor and Description |
---|
BaseCommandController()
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
protected ServletRequestDataBinder |
bindAndValidate(HttpServletRequest request,
java.lang.Object command)
Deprecated.
Bind the parameters of the given request to the given command object.
|
protected boolean |
checkCommand(java.lang.Object command)
Deprecated.
Check if the given command object is a valid for this controller,
i.e.
|
protected ServletRequestDataBinder |
createBinder(HttpServletRequest request,
java.lang.Object command)
Deprecated.
Create a new binder instance for the given command and request.
|
protected java.lang.Object |
createCommand()
Deprecated.
Create a new command instance for the command class of this controller.
|
BindingErrorProcessor |
getBindingErrorProcessor()
Deprecated.
Return the strategy to use for processing binding errors (if any).
|
protected java.lang.Object |
getCommand(HttpServletRequest request)
Deprecated.
Retrieve a command object for the given request.
|
java.lang.Class |
getCommandClass()
Deprecated.
Return the command class for this controller.
|
java.lang.String |
getCommandName()
Deprecated.
Return the name of the command in the model.
|
MessageCodesResolver |
getMessageCodesResolver()
Deprecated.
Return the strategy to use for resolving errors into message codes (if any).
|
PropertyEditorRegistrar[] |
getPropertyEditorRegistrars()
Deprecated.
Return the PropertyEditorRegistrars (if any) to be applied
to every DataBinder that this controller uses.
|
Validator |
getValidator()
Deprecated.
Return the primary Validator for this controller.
|
Validator[] |
getValidators()
Deprecated.
Return the Validators for this controller.
|
WebBindingInitializer |
getWebBindingInitializer()
Deprecated.
Return the WebBindingInitializer (if any) which will apply pre-configured
configuration to every DataBinder that this controller uses.
|
protected void |
initApplicationContext()
Deprecated.
Subclasses can override this for custom initialization behavior.
|
protected void |
initBinder(HttpServletRequest request,
ServletRequestDataBinder binder)
Deprecated.
Initialize the given binder instance, for example with custom editors.
|
boolean |
isValidateOnBinding()
Deprecated.
Return if the Validator should get applied when binding.
|
protected void |
onBind(HttpServletRequest request,
java.lang.Object command)
Deprecated.
Callback for custom post-processing in terms of binding.
|
protected void |
onBind(HttpServletRequest request,
java.lang.Object command,
BindException errors)
Deprecated.
Callback for custom post-processing in terms of binding.
|
protected void |
onBindAndValidate(HttpServletRequest request,
java.lang.Object command,
BindException errors)
Deprecated.
Callback for custom post-processing in terms of binding and validation.
|
protected void |
prepareBinder(ServletRequestDataBinder binder)
Deprecated.
Prepare the given binder, applying the specified MessageCodesResolver,
BindingErrorProcessor and PropertyEditorRegistrars (if any).
|
void |
setBindingErrorProcessor(BindingErrorProcessor bindingErrorProcessor)
Deprecated.
Set the strategy to use for processing binding errors, that is,
required field errors and
PropertyAccessException s. |
void |
setCommandClass(java.lang.Class commandClass)
Deprecated.
Set the command class for this controller.
|
void |
setCommandName(java.lang.String commandName)
Deprecated.
Set the name of the command in the model.
|
void |
setMessageCodesResolver(MessageCodesResolver messageCodesResolver)
Deprecated.
Set the strategy to use for resolving errors into message codes.
|
void |
setPropertyEditorRegistrar(PropertyEditorRegistrar propertyEditorRegistrar)
Deprecated.
Specify a single PropertyEditorRegistrar to be applied
to every DataBinder that this controller uses.
|
void |
setPropertyEditorRegistrars(PropertyEditorRegistrar[] propertyEditorRegistrars)
Deprecated.
Specify multiple PropertyEditorRegistrars to be applied
to every DataBinder that this controller uses.
|
void |
setValidateOnBinding(boolean validateOnBinding)
Deprecated.
Set if the Validator should get applied when binding.
|
void |
setValidator(Validator validator)
Deprecated.
Set the primary Validator for this controller.
|
void |
setValidators(Validator[] validators)
Deprecated.
Set the Validators for this controller.
|
void |
setWebBindingInitializer(WebBindingInitializer webBindingInitializer)
Deprecated.
Specify a WebBindingInitializer which will apply pre-configured
configuration to every DataBinder that this controller uses.
|
protected boolean |
suppressBinding(HttpServletRequest request)
Deprecated.
Return whether to suppress binding for the given request.
|
protected boolean |
suppressValidation(HttpServletRequest request)
Deprecated.
as of Spring 2.0.4, in favor of the
suppressValidation(HttpServletRequest, Object) variant |
protected boolean |
suppressValidation(HttpServletRequest request,
java.lang.Object command)
Deprecated.
Return whether to suppress validation for the given request.
|
protected boolean |
suppressValidation(HttpServletRequest request,
java.lang.Object command,
BindException errors)
Deprecated.
Return whether to suppress validation for the given request.
|
protected boolean |
useDirectFieldAccess()
Deprecated.
Determine whether to use direct field access instead of bean property access.
|
handleRequest, handleRequestInternal, isSynchronizeOnSession, setSynchronizeOnSession
applyCacheSeconds, applyCacheSeconds, cacheForSeconds, cacheForSeconds, checkAndPrepare, checkAndPrepare, getCacheSeconds, getSupportedMethods, isAlwaysMustRevalidate, isRequireSession, isUseCacheControlHeader, isUseCacheControlNoStore, isUseExpiresHeader, preventCaching, setAlwaysMustRevalidate, setCacheSeconds, setRequireSession, setSupportedMethods, setUseCacheControlHeader, setUseCacheControlNoStore, setUseExpiresHeader
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
getApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContext
public static final java.lang.String DEFAULT_COMMAND_NAME
private java.lang.String commandName
private java.lang.Class commandClass
private Validator[] validators
private boolean validateOnBinding
private MessageCodesResolver messageCodesResolver
private BindingErrorProcessor bindingErrorProcessor
private PropertyEditorRegistrar[] propertyEditorRegistrars
private WebBindingInitializer webBindingInitializer
public final void setCommandName(java.lang.String commandName)
public final java.lang.String getCommandName()
public final void setCommandClass(java.lang.Class commandClass)
public final java.lang.Class getCommandClass()
public final void setValidator(Validator validator)
setValidators(Validator[])
to set multiple validators.public final Validator getValidator()
public final void setValidators(Validator[] validators)
public final Validator[] getValidators()
public final void setValidateOnBinding(boolean validateOnBinding)
public final boolean isValidateOnBinding()
public final void setMessageCodesResolver(MessageCodesResolver messageCodesResolver)
Default is null
, i.e. using the default strategy of
the data binder.
public final MessageCodesResolver getMessageCodesResolver()
public final void setBindingErrorProcessor(BindingErrorProcessor bindingErrorProcessor)
PropertyAccessException
s.
Default is null
, that is, using the default strategy
of the data binder.
public final BindingErrorProcessor getBindingErrorProcessor()
public final void setPropertyEditorRegistrar(PropertyEditorRegistrar propertyEditorRegistrar)
Allows for factoring out the registration of PropertyEditors
to separate objects, as an alternative to initBinder(HttpServletRequest, org.springframework.web.bind.ServletRequestDataBinder)
.
public final void setPropertyEditorRegistrars(PropertyEditorRegistrar[] propertyEditorRegistrars)
Allows for factoring out the registration of PropertyEditors
to separate objects, as an alternative to initBinder(HttpServletRequest, org.springframework.web.bind.ServletRequestDataBinder)
.
public final PropertyEditorRegistrar[] getPropertyEditorRegistrars()
public final void setWebBindingInitializer(WebBindingInitializer webBindingInitializer)
Allows for factoring out the entire binder configuration
to separate objects, as an alternative to initBinder(HttpServletRequest, org.springframework.web.bind.ServletRequestDataBinder)
.
public final WebBindingInitializer getWebBindingInitializer()
protected void initApplicationContext()
ApplicationObjectSupport
The default implementation is empty. Called by
ApplicationObjectSupport.initApplicationContext(org.springframework.context.ApplicationContext)
.
protected java.lang.Object getCommand(HttpServletRequest request) throws java.lang.Exception
The default implementation calls createCommand()
.
Subclasses can override this.
request
- current HTTP requestjava.lang.Exception
- if the command object could not be obtainedcreateCommand()
protected final java.lang.Object createCommand() throws java.lang.Exception
This implementation uses BeanUtils.instantiateClass
,
so the command needs to have a no-arg constructor (supposed to be
public, but not required to).
java.lang.Exception
- if the command object could not be instantiatedBeanUtils.instantiateClass(Class)
protected final boolean checkCommand(java.lang.Object command)
command
- the command object to checkprotected final ServletRequestDataBinder bindAndValidate(HttpServletRequest request, java.lang.Object command) throws java.lang.Exception
request
- current HTTP requestcommand
- the command to bind ontojava.lang.Exception
- in case of invalid state or argumentsprotected boolean suppressBinding(HttpServletRequest request)
The default implementation always returns "false". Can be overridden in subclasses to suppress validation, for example, if a special request parameter is set.
request
- current HTTP requestsuppressValidation(HttpServletRequest, java.lang.Object, org.springframework.validation.BindException)
protected ServletRequestDataBinder createBinder(HttpServletRequest request, java.lang.Object command) throws java.lang.Exception
Called by bindAndValidate(HttpServletRequest, java.lang.Object)
. Can be overridden to plug in
custom ServletRequestDataBinder instances.
The default implementation creates a standard ServletRequestDataBinder
and invokes prepareBinder(org.springframework.web.bind.ServletRequestDataBinder)
and initBinder(HttpServletRequest, org.springframework.web.bind.ServletRequestDataBinder)
.
Note that neither prepareBinder(org.springframework.web.bind.ServletRequestDataBinder)
nor initBinder(HttpServletRequest, org.springframework.web.bind.ServletRequestDataBinder)
will
be invoked automatically if you override this method! Call those methods
at appropriate points of your overridden method.
request
- current HTTP requestcommand
- the command to bind ontojava.lang.Exception
- in case of invalid state or argumentsbindAndValidate(HttpServletRequest, java.lang.Object)
,
prepareBinder(org.springframework.web.bind.ServletRequestDataBinder)
,
initBinder(HttpServletRequest, org.springframework.web.bind.ServletRequestDataBinder)
protected final void prepareBinder(ServletRequestDataBinder binder)
createBinder(HttpServletRequest, java.lang.Object)
.binder
- the new binder instancecreateBinder(HttpServletRequest, java.lang.Object)
,
setMessageCodesResolver(org.springframework.validation.MessageCodesResolver)
,
setBindingErrorProcessor(org.springframework.validation.BindingErrorProcessor)
protected boolean useDirectFieldAccess()
prepareBinder(org.springframework.web.bind.ServletRequestDataBinder)
.
Default is "false". Can be overridden in subclasses.
true
)
or bean property access (false
)prepareBinder(org.springframework.web.bind.ServletRequestDataBinder)
,
DataBinder.initDirectFieldAccess()
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws java.lang.Exception
createBinder(HttpServletRequest, java.lang.Object)
.
This method allows you to register custom editors for certain fields of your command class. For instance, you will be able to transform Date objects into a String pattern and back, in order to allow your JavaBeans to have Date properties and still be able to set and display them in an HTML interface.
The default implementation is empty.
request
- current HTTP requestbinder
- the new binder instancejava.lang.Exception
- in case of invalid state or argumentscreateBinder(HttpServletRequest, java.lang.Object)
,
DataBinder.registerCustomEditor(java.lang.Class<?>, java.beans.PropertyEditor)
,
CustomDateEditor
protected void onBind(HttpServletRequest request, java.lang.Object command, BindException errors) throws java.lang.Exception
The default implementation delegates to onBind(HttpServletRequest, Object)
.
request
- current HTTP requestcommand
- the command object to perform further binding onerrors
- validation errors holder, allowing for additional
custom registration of binding errorsjava.lang.Exception
- in case of invalid state or argumentsbindAndValidate(HttpServletRequest, java.lang.Object)
,
onBind(HttpServletRequest, Object)
protected void onBind(HttpServletRequest request, java.lang.Object command) throws java.lang.Exception
Called by the default implementation of the
onBind(HttpServletRequest, Object, BindException)
variant
with all parameters, after standard binding but before validation.
The default implementation is empty.
request
- current HTTP requestcommand
- the command object to perform further binding onjava.lang.Exception
- in case of invalid state or argumentsonBind(HttpServletRequest, Object, BindException)
protected boolean suppressValidation(HttpServletRequest request, java.lang.Object command, BindException errors)
The default implementation delegates to suppressValidation(HttpServletRequest, Object)
.
request
- current HTTP requestcommand
- the command object to validateerrors
- validation errors holder, allowing for additional
custom registration of binding errorsprotected boolean suppressValidation(HttpServletRequest request, java.lang.Object command)
Called by the default implementation of the
suppressValidation(HttpServletRequest, Object, BindException)
variant
with all parameters.
The default implementation delegates to suppressValidation(HttpServletRequest)
.
request
- current HTTP requestcommand
- the command object to validate@Deprecated protected boolean suppressValidation(HttpServletRequest request)
suppressValidation(HttpServletRequest, Object)
variantCalled by the default implementation of the
suppressValidation(HttpServletRequest, Object)
variant
with all parameters.
The default implementation is empty.
request
- current HTTP requestprotected void onBindAndValidate(HttpServletRequest request, java.lang.Object command, BindException errors) throws java.lang.Exception
The default implementation is empty.
request
- current HTTP requestcommand
- the command object, still allowing for further bindingerrors
- validation errors holder, allowing for additional
custom validationjava.lang.Exception
- in case of invalid state or argumentsbindAndValidate(HttpServletRequest, java.lang.Object)
,
Errors