|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.springframework.context.support.ApplicationObjectSupport
org.springframework.web.context.support.WebApplicationObjectSupport
org.springframework.web.servlet.support.WebContentGenerator
org.springframework.web.servlet.mvc.AbstractController
org.shept.org.springframework.web.servlet.mvc.delegation.DelegatingController
public class DelegatingController
Controller
implementation that allows multiple request types to be handled by the same
class.
The design is inspired by the org.springframework.web.servlet.mvc.delegating.DelegatingController but there are
some important differences. The DelegatingController is specifically designed to support repetitive elements on a WebPage
such as Tables, Schedules, Filtering and searching or any combination of these elements and your own custom requirements.
This is accomplished by delegating to predefined handlers aka WebComponent
A number of handlers for filters and tables are already predefined and ready to use. By subclassing AbstractComponent
and implementing the WebComponent you can extend the controller with custom Components.
A component is associated with some part of your command object. To resolve the association between components and
your command object your command object needs to implement the SubCommandProvider Interface which will
inform the controller about the components it supports. Basically the SubCommandProvider Interface specifies a map of
bean pathnames and the (sub-)command objects at the nodes of each pathName. See DefaultCommandObject for an example.
This design is very flexible and allows for infinite extension as elements may repeat an infinte number of times requiring just a single handler to take care of them. A good example is a WebPage where you search for customers and their associated data, e.g. addresses, contracts, history information e.t.c. Its easily possible to expand the searchpage towards the end and so you can group a lot of editable information without writing much code.
Now we need to match a form submission with the component handler in duty. By convention each form submission for a component
other than root needs a prefix of the same bean pathname which is returned the SubCommandProvider interface.
Two resolvers provide this solution: The ComponentNameResolver will match the the pathname of the associated handler and the
form submission. In a second step the WebActionResolver will supply the paramters of the form submission with a
WebActionToken gathering all the information from the form submission wrapping it with command object and component
in a ComponentToken for further processing by the target handler.
The DelegatingController does not bind request parameters to the command object this has to be done by the invoked handler.
This allows for full control over the entire binder setup and usage, including the invocation of Validators
and the subsequent evaluation of binding/validation errors. All error handling is in the responsibility of the invoked handler
Return values can be a map containing model attributes or ModelAndView or RedirectView objects. If there is no
model name or redirect url specified then default values will be provided. The configured
RequestToViewNameTranslator will be used to determine the view name.
In case of a RedirectView it will use the redirectViewName field which is be default the controllers name which should be
by convention servlet pathName so redirected views implement by default the get-after-post strategy.
WebActionResolver,
ComponentNameResolver,
SubmitActionResolver,
LastModified.getLastModified(javax.servlet.http.HttpServletRequest),
ServletRequestDataBinder| Field Summary | |
|---|---|
private WebActionResolver |
actionResolver
Delegate that knows how to determine method names and submission values from incoming requests |
private Class<Object> |
commandClass
Command class specification |
static String |
DEFAULT_COMMAND_NAME
Default command name used for binding command objects: "command" |
private WebComponent[] |
delegates
components handlers |
private String |
formView
formView - this is the fileName |
static String |
LAST_MODIFIED_METHOD_SUFFIX
Suffix for last-modified methods |
static String |
PAGE_NOT_FOUND_LOG_CATEGORY
Log category to use when no mapped handler is found for a request. |
protected static org.apache.commons.logging.Log |
pageNotFoundLogger
Additional logger to use when no mapped handler is found for a request. |
private String |
redirectUrl
Redirection url - by default this should be the name of the bean (set via BeanNameAware) |
private org.springframework.web.bind.support.WebBindingInitializer |
webBindingInitializer
Optional strategy for pre-initializing data binding |
| Fields inherited from class org.springframework.web.servlet.support.WebContentGenerator |
|---|
METHOD_GET, METHOD_HEAD, METHOD_POST |
| Fields inherited from class org.springframework.context.support.ApplicationObjectSupport |
|---|
logger |
| Constructor Summary | |
|---|---|
DelegatingController()
|
|
| Method Summary | |
|---|---|
void |
afterPropertiesSet()
|
protected ComponentDataBinder |
createBinder(javax.servlet.http.HttpServletRequest request,
Object command)
Create a new binder instance for the given command and request. |
protected String |
getCommandName(Object command)
Return the command name to use for the given command object. |
protected Object |
getCommandObject(javax.servlet.http.HttpServletRequest request,
Class clazz)
Create a new command object of the given class. |
String |
getFormView()
|
long |
getLastModified(javax.servlet.http.HttpServletRequest request)
Try to find an XXXXLastModified method, where XXXX is the name of a handler. |
String |
getRedirectUrl()
|
org.springframework.web.bind.support.WebBindingInitializer |
getWebBindingInitializer()
Return the WebBindingInitializer (if any) which will apply pre-configured configuration to every DataBinder that this controller uses. |
protected org.springframework.web.servlet.ModelAndView |
handleNoSuchRequestHandlingMethod(org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException ex,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Handle the case where no request handler method was found. |
protected org.springframework.web.servlet.ModelAndView |
handleRequestInternal(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Determine a handler method and invoke it. |
protected void |
initBinder(javax.servlet.http.HttpServletRequest request,
ComponentDataBinder binder)
Initialize the given binder instance, for example with custom editors. |
protected org.springframework.web.servlet.ModelAndView |
massageReturnValueIfNecessary(Object returnValue)
Processes the return value of a handler method to ensure that it either returns null or an instance of ModelAndView. |
protected void |
postProcessModel(javax.servlet.http.HttpServletRequest request,
org.springframework.web.servlet.ModelAndView modelAndView)
|
private Map<String,Object> |
prepareComponentPathForLookup(Map<String,Object> components)
put a colon '.' at the end of non empty pathNames |
void |
setActionResolver(WebActionResolver actionResolver)
|
void |
setBeanName(String name)
|
void |
setCommandClass(Class<Object> commandClass)
|
void |
setDelegates(WebComponent[] delegates)
|
void |
setFormView(String formView)
|
void |
setRedirectUrl(String viewName)
|
void |
setWebBindingInitializer(org.springframework.web.bind.support.WebBindingInitializer webBindingInitializer)
Specify a WebBindingInitializer which will apply pre-configured configuration to every DataBinder that this controller uses. |
| Methods inherited from class org.springframework.web.servlet.mvc.AbstractController |
|---|
handleRequest, isSynchronizeOnSession, setSynchronizeOnSession |
| Methods inherited from class org.springframework.web.servlet.support.WebContentGenerator |
|---|
applyCacheSeconds, applyCacheSeconds, cacheForSeconds, cacheForSeconds, checkAndPrepare, checkAndPrepare, getCacheSeconds, getSupportedMethods, isRequireSession, isUseCacheControlHeader, isUseCacheControlNoStore, isUseExpiresHeader, preventCaching, setCacheSeconds, setRequireSession, setSupportedMethods, setUseCacheControlHeader, setUseCacheControlNoStore, setUseExpiresHeader |
| Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport |
|---|
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext |
| Methods inherited from class org.springframework.context.support.ApplicationObjectSupport |
|---|
getApplicationContext, getMessageSourceAccessor, initApplicationContext, requiredContextClass, setApplicationContext |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String LAST_MODIFIED_METHOD_SUFFIX
public static final String DEFAULT_COMMAND_NAME
public static final String PAGE_NOT_FOUND_LOG_CATEGORY
pageNotFoundLogger,
Constant Field Valuesprotected static final org.apache.commons.logging.Log pageNotFoundLogger
PAGE_NOT_FOUND_LOG_CATEGORYprivate WebActionResolver actionResolver
private org.springframework.web.bind.support.WebBindingInitializer webBindingInitializer
private WebComponent[] delegates
private String redirectUrl
private String formView
private Class<Object> commandClass
| Constructor Detail |
|---|
public DelegatingController()
| Method Detail |
|---|
public void setActionResolver(WebActionResolver actionResolver)
actionResolver - the actionResolver to setpublic void setDelegates(WebComponent[] delegates)
delegates - the delegates to setpublic void setCommandClass(Class<Object> commandClass)
commandClass - the commandClass to setpublic final void setWebBindingInitializer(org.springframework.web.bind.support.WebBindingInitializer webBindingInitializer)
Allows for factoring out the entire binder configuration
to separate objects, as an alternative to initBinder(javax.servlet.http.HttpServletRequest, org.shept.org.springframework.web.bind.support.ComponentDataBinder).
public final org.springframework.web.bind.support.WebBindingInitializer getWebBindingInitializer()
public long getLastModified(javax.servlet.http.HttpServletRequest request)
getLastModified in interface org.springframework.web.servlet.mvc.LastModifiedLastModified.getLastModified(HttpServletRequest)
protected org.springframework.web.servlet.ModelAndView handleRequestInternal(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws Exception
handleRequestInternal in class org.springframework.web.servlet.mvc.AbstractControllerExceptionMethodNameResolver.getHandlerMethodName(javax.servlet.http.HttpServletRequest),
#invokeNamedMethod,
handleNoSuchRequestHandlingMethod(org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)private Map<String,Object> prepareComponentPathForLookup(Map<String,Object> components)
- componentPathName - pathNames -
protected org.springframework.web.servlet.ModelAndView handleNoSuchRequestHandlingMethod(org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException ex,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws Exception
The default implementation logs a warning and sends an HTTP 404 error. Alternatively, a fallback view could be chosen, or the NoSuchRequestHandlingMethodException could be rethrown as-is.
ex - the NoSuchRequestHandlingMethodException to be handledrequest - current HTTP requestresponse - current HTTP response
null if handled directly
Exception - an Exception that should be thrown as result of the servlet requestprotected org.springframework.web.servlet.ModelAndView massageReturnValueIfNecessary(Object returnValue)
null or an instance of ModelAndView. When returning a Map,
the Map instance is wrapped in a new ModelAndView instance.
protected Object getCommandObject(javax.servlet.http.HttpServletRequest request,
Class clazz)
throws Exception
This implementation uses BeanUtils.instantiateClass,
so commands need to have public no-arg constructors.
Subclasses can override this implementation if desired.
Exception - if the command object could not be instantiatedBeanUtils.instantiateClass(Class)
protected ComponentDataBinder createBinder(javax.servlet.http.HttpServletRequest request,
Object command)
throws Exception
Called by bind. Can be overridden to plug in custom
ServletRequestDataBinder subclasses.
The default implementation creates a standard ServletRequestDataBinder,
and invokes initBinder. Note that initBinder
will not be invoked if you override this method!
request - current HTTP requestcommand - the command to bind onto
Exception - in case of invalid state or arguments#bind,
initBinder(javax.servlet.http.HttpServletRequest, org.shept.org.springframework.web.bind.support.ComponentDataBinder)protected String getCommandName(Object command)
Default is "command".
command - the command object
DEFAULT_COMMAND_NAME
protected void initBinder(javax.servlet.http.HttpServletRequest request,
ComponentDataBinder binder)
throws Exception
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.
Note: the command object is not directly passed to this method, but it's available
via DataBinder.getTarget()
request - current HTTP requestbinder - new binder instance
Exception - in case of invalid state or argumentscreateBinder(javax.servlet.http.HttpServletRequest, java.lang.Object),
DataBinder.registerCustomEditor(java.lang.Class, java.beans.PropertyEditor),
CustomDateEditor
protected void postProcessModel(javax.servlet.http.HttpServletRequest request,
org.springframework.web.servlet.ModelAndView modelAndView)
throws Exception
Exceptionpublic void setBeanName(String name)
setBeanName in interface org.springframework.beans.factory.BeanNameAwarepublic String getRedirectUrl()
public void setRedirectUrl(String viewName)
viewName - the viewName to set
public void afterPropertiesSet()
throws Exception
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanExceptionpublic String getFormView()
public void setFormView(String formView)
formView - the formView to set
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||