java.lang.Object | |||||
↳ | org.springframework.context.support.ApplicationObjectSupport | ||||
↳ | org.springframework.web.portlet.context.PortletApplicationObjectSupport | ||||
↳ | org.springframework.web.portlet.handler.PortletContentGenerator | ||||
↳ | org.springframework.web.portlet.mvc.AbstractController | ||||
↳ | org.springframework.web.portlet.mvc.BaseCommandController |
Known Direct Subclasses |
Known Indirect Subclasses |
This class is deprecated.
as of Spring 3.0, in favor of annotated controllers
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 realize 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()
methods 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. |
Thanks to Rainer Schmitz and Nick Lothian for their suggestions!
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
String | DEFAULT_COMMAND_NAME |
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.context.support.ApplicationObjectSupport
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Return the strategy to use for processing binding errors (if any).
| |||||||||||
Return the command class for this controller.
| |||||||||||
Return the name of the command in the model.
| |||||||||||
Return the strategy to use for resolving errors into message codes (if any).
| |||||||||||
Return the PropertyEditorRegistrars (if any) to be applied
to every DataBinder that this controller uses.
| |||||||||||
Return the Validators for this controller.
| |||||||||||
Return the WebBindingInitializer (if any) which will apply pre-configured
configuration to every DataBinder that this controller uses.
| |||||||||||
Return if the Validator should get applied when binding.
| |||||||||||
Set the strategy to use for processing binding errors, that is,
required field errors and
PropertyAccessException s. | |||||||||||
Set the command class for this controller.
| |||||||||||
Set the name of the command in the model.
| |||||||||||
Set the strategy to use for resolving errors into message codes.
| |||||||||||
Specify a single PropertyEditorRegistrar to be applied
to every DataBinder that this controller uses.
| |||||||||||
Specify one or more PropertyEditorRegistrars to be applied
to every DataBinder that this controller uses.
| |||||||||||
Set if the Validator should get applied when binding.
| |||||||||||
Set the primary Validator for this controller.
| |||||||||||
Set the Validators for this controller.
| |||||||||||
Specify a WebBindingInitializer which will apply pre-configured
configuration to every DataBinder that this controller uses.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Bind the parameters of the given request to the given command object.
| |||||||||||
Check if the given command object is a valid for this controller,
i.e.
| |||||||||||
Create a new binder instance for the given command and request.
| |||||||||||
Create a new command instance for the command class of this controller.
| |||||||||||
Retrieve a command object for the given request.
| |||||||||||
Get the command object cached for the render phase.
| |||||||||||
Return the name of the session attribute that holds
the render phase command object for this form controller.
| |||||||||||
Get the bind and validation errors cached for the render phase.
| |||||||||||
Return the name of the session attribute that holds
the render phase command object for this form controller.
| |||||||||||
Subclasses can override this for custom initialization behavior.
| |||||||||||
Initialize the given binder instance, for example with custom editors.
| |||||||||||
Callback for custom post-processing in terms of binding.
| |||||||||||
Callback for custom post-processing in terms of binding.
| |||||||||||
Callback for custom post-processing in terms of binding and validation.
| |||||||||||
Prepare the given binder, applying the specified MessageCodesResolver,
BindingErrorProcessor and PropertyEditorRegistrars (if any).
| |||||||||||
Set the command object and errors object for the render phase.
| |||||||||||
Return whether to suppress binding for the given request.
| |||||||||||
Return whether to suppress validation for the given request.
| |||||||||||
Determine whether to use direct field access instead of bean property access.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.web.portlet.mvc.AbstractController
| |||||||||||
From class
org.springframework.web.portlet.handler.PortletContentGenerator
| |||||||||||
From class
org.springframework.web.portlet.context.PortletApplicationObjectSupport
| |||||||||||
From class
org.springframework.context.support.ApplicationObjectSupport
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
org.springframework.context.ApplicationContextAware
| |||||||||||
From interface
org.springframework.web.portlet.context.PortletContextAware
| |||||||||||
From interface
org.springframework.web.portlet.mvc.Controller
|
Return the strategy to use for processing binding errors (if any).
Return the strategy to use for resolving errors into message codes (if any).
Return the PropertyEditorRegistrars (if any) to be applied to every DataBinder that this controller uses.
Return the WebBindingInitializer (if any) which will apply pre-configured configuration to every DataBinder that this controller uses.
Return if the Validator should get applied when binding.
Set the strategy to use for processing binding errors, that is,
required field errors and PropertyAccessException
s.
Default is null
, i.e. using the default strategy of
the data binder.
Set the command class for this controller. An instance of this class gets populated and validated on each request.
Set the name of the command in the model. The command object will be included in the model under this name.
Set the strategy to use for resolving errors into message codes. Applies the given strategy to all data binders used by this controller.
Default is null
, i.e. using the default strategy of the data binder.
Specify a single PropertyEditorRegistrar to be applied to every DataBinder that this controller uses.
Allows for factoring out the registration of PropertyEditors
to separate objects, as an alternative to initBinder
.
Specify one or more PropertyEditorRegistrars to be applied to every DataBinder that this controller uses.
Allows for factoring out the registration of PropertyEditors
to separate objects, as alternative to initBinder
.
Set if the Validator should get applied when binding.
Set the primary Validator for this controller. The Validator
must support the specified command class. If there are one
or more existing validators set already when this method is
called, only the specified validator will be kept. Use
setValidators(Validator[])
to set multiple validators.
Set the Validators for this controller. The Validator must support the specified command class.
Specify a WebBindingInitializer which will apply pre-configured configuration to every DataBinder that this controller uses.
Allows for factoring out the entire binder configuration
to separate objects, as an alternative to initBinder(PortletRequest, PortletRequestDataBinder)
.
Bind the parameters of the given request to the given command object.
request | current portlet request |
---|---|
command | the command to bind onto |
Exception | in case of invalid state or arguments |
---|
Check if the given command object is a valid for this controller, i.e. its command class.
command | the command object to check |
---|
Create a new binder instance for the given command and request.
Called by bindAndValidate
. Can be overridden to plug in
custom PortletRequestDataBinder instances.
The default implementation creates a standard PortletRequestDataBinder and
invokes prepareBinder
and initBinder
.
Note that neither prepareBinder
nor initBinder
will be invoked automatically if you override this method! Call those methods
at appropriate points of your overridden method.
request | current portlet request |
---|---|
command | the command to bind onto |
Exception | in case of invalid state or arguments |
---|
Create a new command instance for the command class of this controller.
This implementation uses BeanUtils.instantiateClass
,
so the command needs to have a no-arg constructor (supposed to be
public, but not required to).
Exception | if the command object could not be instantiated |
---|
Retrieve a command object for the given request.
The default implementation calls createCommand()
.
Subclasses can override this.
request | current portlet request |
---|
Exception |
---|
Get the command object cached for the render phase.
PortletException |
---|
Return the name of the session attribute that holds the render phase command object for this form controller.
Get the bind and validation errors cached for the render phase.
PortletException |
---|
Return the name of the session attribute that holds the render phase command object for this form controller.
Subclasses can override this for custom initialization behavior.
The default implementation is empty. Called by
initApplicationContext(org.springframework.context.ApplicationContext)
.
Initialize the given binder instance, for example with custom editors.
Called by createBinder
.
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 portlet request |
---|---|
binder | new binder instance |
Exception | in case of invalid state or arguments |
---|
Callback for custom post-processing in terms of binding.
Called by the default implementation of the onBind
version with
all parameters, after standard binding but before validation.
The default implementation is empty.
request | current portlet request |
---|---|
command | the command object to perform further binding on |
Exception | in case of invalid state or arguments |
---|
Callback for custom post-processing in terms of binding. Called on each submit, after standard binding but before validation.
The default implementation delegates to onBind(request, command)
.
request | current portlet request |
---|---|
command | the command object to perform further binding on |
errors | validation errors holder, allowing for additional custom registration of binding errors |
Exception | in case of invalid state or arguments |
---|
Callback for custom post-processing in terms of binding and validation. Called on each submit, after standard binding and validation, but before error evaluation.
The default implementation is empty.
request | current portlet request |
---|---|
command | the command object, still allowing for further binding |
errors | validation errors holder, allowing for additional custom validation |
Exception | in case of invalid state or arguments |
---|
Prepare the given binder, applying the specified MessageCodesResolver,
BindingErrorProcessor and PropertyEditorRegistrars (if any).
Called by createBinder
.
binder | the new binder instance |
---|
Set the command object and errors object for the render phase.
request | the current action request |
---|---|
command | the command object to preserve for the render phase |
errors | the errors from binding and validation to preserve for the render phase |
Exception |
---|
Return whether to suppress binding for the given 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 portlet request |
---|
Return whether to suppress validation for the given 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 portlet request |
---|
Determine whether to use direct field access instead of bean property access.
Applied by prepareBinder
.
The default is false
. Can be overridden in subclasses.