java.lang.Object | ||||
↳ | GenericPortlet | |||
↳ | org.springframework.web.portlet.GenericPortletBean | |||
↳ | org.springframework.web.portlet.FrameworkPortlet | |||
↳ | org.springframework.web.portlet.DispatcherPortlet |
Central dispatcher for use within the Portlet MVC framework, e.g. for web UI controllers. Dispatches to registered handlers for processing a portlet request.
This portlet is very flexible: It can be used with just about any workflow, with the installation of the appropriate adapter classes. It offers the following functionality that distinguishes it from other request-driven portlet MVC frameworks:
HandlerMapping
implementation - pre-built or provided
as part of an application - to control the routing of requests to handler objects.
Default is a DefaultAnnotationHandlerMapping
.
HandlerMapping objects can be defined as beans in the portlet's application context,
implementing the HandlerMapping interface, overriding the default HandlerMapping if present.
HandlerMappings can be given any bean name (they are tested by type).
HandlerAdapter
; this allows for using any handler interface.
The default adapter is SimpleControllerHandlerAdapter
for Spring's Controller
interface.
A default AnnotationMethodHandlerAdapter
will be registered as well. HandlerAdapter objects can be added as beans in the
application context, overriding the default HandlerAdapter. Like HandlerMappings,
HandlerAdapters can be given any bean name (they are tested by type).
HandlerExceptionResolver
, for example mapping certain exceptions to
error pages. Default is none. Additional HandlerExceptionResolvers can be added
through the application context. HandlerExceptionResolver can be given any
bean name (they are tested by type).
ViewResolver
implementation, resolving symbolic view names into View objects. Default is
InternalResourceViewResolver
.
ViewResolver objects can be added as beans in the application context,
overriding the default ViewResolver. ViewResolvers can be given any bean name
(they are tested by type).
PortletMultipartResolver
implementation.
An implementations for Jakarta Commons FileUpload is included:
CommonsPortletMultipartResolver
.
The MultipartResolver bean name is "portletMultipartResolver"; default is none.
NOTE: The @RequestMapping
annotation will only be processed
if a corresponding HandlerMapping
(for type level annotations)
and/or HandlerAdapter
(for method level annotations)
is present in the dispatcher. This is the case by default.
However, if you are defining custom HandlerMappings
or
HandlerAdapters
, then you need to make sure that a
corresponding custom DefaultAnnotationHandlerMapping
and/or AnnotationMethodHandlerAdapter
is defined as well
- provided that you intend to use @RequestMapping
.
A web application can define any number of DispatcherPortlets.
Each portlet will operate in its own namespace, loading its own application
context with mappings, handlers, etc. Only the root application context
as loaded by ContextLoaderListener
,
if any, will be shared.
Thanks to Rainer Schmitz and Nick Lothian for their suggestions!
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
String | ACTION_EXCEPTION_RENDER_PARAMETER | This render parameter is used to indicate forward to the render phase that an exception occurred during the action phase. | |||||||||
String | DEFAULT_VIEW_RENDERER_URL | Default URL to ViewRendererServlet. | |||||||||
String | HANDLER_ADAPTER_BEAN_NAME | Well-known name for the HandlerAdapter object in the bean factory for this namespace. | |||||||||
String | HANDLER_EXCEPTION_RESOLVER_BEAN_NAME | Well-known name for the HandlerExceptionResolver object in the bean factory for this namespace. | |||||||||
String | HANDLER_MAPPING_BEAN_NAME | Well-known name for the HandlerMapping object in the bean factory for this namespace. | |||||||||
String | MULTIPART_RESOLVER_BEAN_NAME | Well-known name for the PortletMultipartResolver object in the bean factory for this namespace. | |||||||||
String | PAGE_NOT_FOUND_LOG_CATEGORY | Log category to use when no mapped handler is found for a request. | |||||||||
String | VIEW_RESOLVER_BEAN_NAME | Well-known name for the ViewResolver object in the bean factory for this namespace. |
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.web.portlet.FrameworkPortlet
|
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
ACTION_EXCEPTION_SESSION_ATTRIBUTE | Unlike the Servlet version of this class, we have to deal with the two-phase nature of the portlet request. | ||||||||||
pageNotFoundLogger | Additional logger to use when no mapped handler is found for a request. |
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.web.portlet.FrameworkPortlet
| |||||||||||
From class
org.springframework.web.portlet.GenericPortletBean
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Obtain this portlet's PortletMultipartResolver, if any.
| |||||||||||
This implementation calls
initStrategies(ApplicationContext) . | |||||||||||
Set whether to detect all HandlerAdapter beans in this portlet's context.
| |||||||||||
Set whether to detect all HandlerExceptionResolver beans in this portlet's context.
| |||||||||||
Set whether to detect all HandlerMapping beans in this portlet's context.
| |||||||||||
Set whether to detect all ViewResolver beans in this portlet's context.
| |||||||||||
Set the URL to the ViewRendererServlet.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Convert the request into a multipart request, and make multipart resolver available.
| |||||||||||
Create a default strategy.
| |||||||||||
Processes the actual dispatching to the handler for action requests.
| |||||||||||
Processes the actual dispatching to the handler for event requests.
| |||||||||||
Actually render the given view.
| |||||||||||
Processes the actual dispatching to the handler for render requests.
| |||||||||||
Processes the actual dispatching to the handler for resource requests.
| |||||||||||
Expose the given action exception to the given response.
| |||||||||||
Create a List of default strategy objects for the given strategy interface.
| |||||||||||
Return the default strategy object for the given strategy interface.
| |||||||||||
Return the HandlerExecutionChain for this request.
| |||||||||||
Return the HandlerAdapter for this handler object.
| |||||||||||
Refresh the strategy objects that this portlet uses.
| |||||||||||
No handler found -> throw appropriate exception.
| |||||||||||
Determine an error ModelAndView via the registered HandlerExceptionResolvers.
| |||||||||||
Determine an error ModelAndView via the registered HandlerExceptionResolvers.
| |||||||||||
Render the given ModelAndView.
| |||||||||||
Resolve the given view name into a View object (to be rendered).
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.web.portlet.FrameworkPortlet
| |||||||||||
From class
org.springframework.web.portlet.GenericPortletBean
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
org.springframework.context.ApplicationListener
| |||||||||||
From interface
org.springframework.context.EnvironmentAware
|
This render parameter is used to indicate forward to the render phase that an exception occurred during the action phase.
Default URL to ViewRendererServlet. This bridge servlet is used to convert
portlet render requests to servlet requests in order to leverage the view support
in the org.springframework.web.view
package.
Well-known name for the HandlerAdapter object in the bean factory for this namespace. Only used when "detectAllHandlerAdapters" is turned off.
Well-known name for the HandlerExceptionResolver object in the bean factory for this namespace. Only used when "detectAllHandlerExceptionResolvers" is turned off.
Well-known name for the HandlerMapping object in the bean factory for this namespace. Only used when "detectAllHandlerMappings" is turned off.
Well-known name for the PortletMultipartResolver object in the bean factory for this namespace.
Log category to use when no mapped handler is found for a request.
Well-known name for the ViewResolver object in the bean factory for this namespace.
Unlike the Servlet version of this class, we have to deal with the two-phase nature of the portlet request. To do this, we need to pass forward any exception that occurs during the action phase, so that it can be displayed in the render phase. The only direct way to pass things forward and preserve them for each render request is through render parameters, but these are limited to String objects and we need to pass the Exception itself. The only other way to do this is in the session. The bad thing about using the session is that we have no way of knowing when we are done re-rendering the request and so we don't know when we can remove the objects from the session. So we will end up polluting the session with an old exception when we finally leave the render phase of one request and move on to something else.
Additional logger to use when no mapped handler is found for a request.
Obtain this portlet's PortletMultipartResolver, if any.
null
if none (indicating that no multipart support is available)
This implementation calls initStrategies(ApplicationContext)
.
context | the current Portlet ApplicationContext |
---|
Set whether to detect all HandlerAdapter beans in this portlet's context. Else, just a single bean with name "handlerAdapter" will be expected.
Default is "true". Turn this off if you want this portlet to use a single HandlerAdapter, despite multiple HandlerAdapter beans being defined in the context.
Set whether to detect all HandlerExceptionResolver beans in this portlet's context. Else, just a single bean with name "handlerExceptionResolver" will be expected.
Default is true. Turn this off if you want this portlet to use a single HandlerExceptionResolver, despite multiple HandlerExceptionResolver beans being defined in the context.
Set whether to detect all HandlerMapping beans in this portlet's context. Else, just a single bean with name "handlerMapping" will be expected.
Default is true. Turn this off if you want this portlet to use a single HandlerMapping, despite multiple HandlerMapping beans being defined in the context.
Set whether to detect all ViewResolver beans in this portlet's context. Else, just a single bean with name "viewResolver" will be expected.
Default is true. Turn this off if you want this portlet to use a single ViewResolver, despite multiple ViewResolver beans being defined in the context.
Set the URL to the ViewRendererServlet. That servlet is used to ultimately render all views in the portlet application.
Convert the request into a multipart request, and make multipart resolver available. If no multipart resolver is set, simply use the existing request.
request | current HTTP request |
---|
MultipartException |
---|
Create a default strategy.
The default implementation uses
createBean(Class, int, boolean)
.
context | the current Portlet ApplicationContext |
---|---|
clazz | the strategy implementation class to instantiate |
Processes the actual dispatching to the handler for action requests.
The handler will be obtained by applying the portlet's HandlerMappings in order. The HandlerAdapter will be obtained by querying the portlet's installed HandlerAdapters to find the first that supports the handler class.
request | current portlet action request |
---|---|
response | current portlet Action response |
Exception | in case of any kind of processing failure |
---|
Processes the actual dispatching to the handler for event requests.
The handler will be obtained by applying the portlet's HandlerMappings in order. The HandlerAdapter will be obtained by querying the portlet's installed HandlerAdapters to find the first that supports the handler class.
request | current portlet action request |
---|---|
response | current portlet Action response |
Exception | in case of any kind of processing failure |
---|
Actually render the given view.
The default implementation delegates to
ViewRendererServlet
.
view | the View to render |
---|---|
model | the associated model |
request | current portlet render request |
response | current portlet render response |
Exception | if there's a problem rendering the view |
---|
Processes the actual dispatching to the handler for render requests.
The handler will be obtained by applying the portlet's HandlerMappings in order. The HandlerAdapter will be obtained by querying the portlet's installed HandlerAdapters to find the first that supports the handler class.
request | current portlet render request |
---|---|
response | current portlet render response |
Exception | in case of any kind of processing failure |
---|
Processes the actual dispatching to the handler for resource requests.
The handler will be obtained by applying the portlet's HandlerMappings in order. The HandlerAdapter will be obtained by querying the portlet's installed HandlerAdapters to find the first that supports the handler class.
request | current portlet render request |
---|---|
response | current portlet render response |
Exception | in case of any kind of processing failure |
---|
Expose the given action exception to the given response.
request | current portlet request |
---|---|
response | current portlet response |
ex | the action exception (may also come from an event phase) |
Create a List of default strategy objects for the given strategy interface.
The default implementation uses the "DispatcherPortlet.properties" file (in the same package as the DispatcherPortlet class) to determine the class names. It instantiates the strategy objects and satisifies ApplicationContextAware if necessary.
context | the current Portlet ApplicationContext |
---|---|
strategyInterface | the strategy interface |
Return the default strategy object for the given strategy interface.
The default implementation delegates to getDefaultStrategies(ApplicationContext, Class
,
expecting a single object in the list.
context | the current Portlet ApplicationContext |
---|---|
strategyInterface | the strategy interface |
Return the HandlerExecutionChain for this request. Try all handler mappings in order.
request | current portlet request |
---|
Exception |
---|
Return the HandlerAdapter for this handler object.
handler | the handler object to find an adapter for |
---|
if no HandlerAdapter can be found for the handler. This is a fatal error. | |
PortletException |
Refresh the strategy objects that this portlet uses.
May be overridden in subclasses in order to initialize further strategy objects.
No handler found -> throw appropriate exception.
request | current portlet request |
---|---|
response | current portlet response |
Exception | if preparing the response failed |
---|
Determine an error ModelAndView via the registered HandlerExceptionResolvers.
request | current portlet request |
---|---|
response | current portlet response |
handler | the executed handler, or null if none chosen at the time of the exception (for example, if multipart resolution failed) |
ex | the exception that got thrown during handler execution |
Exception | if no error ModelAndView found |
---|
Determine an error ModelAndView via the registered HandlerExceptionResolvers.
request | current portlet request |
---|---|
response | current portlet response |
handler | the executed handler, or null if none chosen at the time of the exception (for example, if multipart resolution failed) |
ex | the exception that got thrown during handler execution |
Exception | if no error ModelAndView found |
---|
Render the given ModelAndView. This is the last stage in handling a request. It may involve resolving the view by name.
mv | the ModelAndView to render |
---|---|
request | current portlet render request |
response | current portlet render response |
Exception | if there's a problem rendering the view |
---|
Resolve the given view name into a View object (to be rendered).
Default implementations asks all ViewResolvers of this dispatcher. Can be overridden for custom resolution strategies, potentially based on specific model attributes or request parameters.
viewName | the name of the view to resolve |
---|---|
model | the model to be passed to the view |
request | current portlet render request |
Exception | if the view cannot be resolved (typically in case of problems creating an actual View object) |
---|