public class AnnotationMethodHandlerAdapter extends PortletContentGenerator implements HandlerAdapter, org.springframework.core.Ordered, org.springframework.beans.factory.BeanFactoryAware
HandlerAdapter
interface that maps handler methods based on portlet modes, action/render phases
and request parameters expressed through the RequestMapping annotation.
Supports request parameter binding through the RequestParam annotation.
Also supports the ModelAttribute annotation for exposing model attribute
values to the view, as well as InitBinder for binder initialization methods
and SessionAttributes for automatic session management of specific attributes.
This adapter can be customized through various bean properties.
A common use case is to apply shared binder initialization logic through
a custom WebBindingInitializer.
setWebBindingInitializer(org.springframework.web.bind.support.WebBindingInitializer),
setSessionAttributeStore(org.springframework.web.bind.support.SessionAttributeStore)| Modifier and Type | Field and Description |
|---|---|
static String |
IMPLICIT_MODEL_RENDER_PARAMETER |
static String |
IMPLICIT_MODEL_SESSION_ATTRIBUTE |
| Constructor and Description |
|---|
AnnotationMethodHandlerAdapter() |
| Modifier and Type | Method and Description |
|---|---|
protected PortletRequestDataBinder |
createBinder(PortletRequest request,
Object target,
String objectName)
Template method for creating a new PortletRequestDataBinder instance.
|
protected ModelAndView |
doHandle(PortletRequest request,
PortletResponse response,
Object handler) |
int |
getOrder() |
void |
handleAction(ActionRequest request,
ActionResponse response,
Object handler)
Use the given handler to handle this action request.
|
void |
handleEvent(EventRequest request,
EventResponse response,
Object handler)
Use the given handler to handle this event request.
|
ModelAndView |
handleRender(RenderRequest request,
RenderResponse response,
Object handler)
Use the given handler to handle this render request.
|
ModelAndView |
handleResource(ResourceRequest request,
ResourceResponse response,
Object handler)
Use the given handler to handle this resource request.
|
void |
setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) |
void |
setCacheSecondsForSessionAttributeHandlers(int cacheSecondsForSessionAttributeHandlers)
Cache content produced by
@SessionAttributes annotated handlers
for the given number of seconds. |
void |
setCustomArgumentResolver(org.springframework.web.bind.support.WebArgumentResolver argumentResolver)
Set a custom WebArgumentResolver to use for special method parameter types.
|
void |
setCustomArgumentResolvers(org.springframework.web.bind.support.WebArgumentResolver[] argumentResolvers)
Set one or more custom WebArgumentResolvers to use for special method
parameter types.
|
void |
setCustomModelAndViewResolver(org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver customModelAndViewResolver)
Set a custom ModelAndViewResolvers to use for special method return types.
|
void |
setCustomModelAndViewResolvers(org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver[] customModelAndViewResolvers)
Set one or more custom ModelAndViewResolvers to use for special method return types.
|
void |
setOrder(int order)
Specify the order value for this HandlerAdapter bean.
|
void |
setParameterNameDiscoverer(org.springframework.core.ParameterNameDiscoverer parameterNameDiscoverer)
Set the ParameterNameDiscoverer to use for resolving method parameter
names if needed (e.g.
|
void |
setSessionAttributeStore(org.springframework.web.bind.support.SessionAttributeStore sessionAttributeStore)
Specify the strategy to store session attributes with.
|
void |
setSynchronizeOnSession(boolean synchronizeOnSession)
Set if controller execution should be synchronized on the session,
to serialize parallel invocations from the same client.
|
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.
|
boolean |
supports(Object handler)
Given a handler instance, return whether or not this HandlerAdapter can
support it.
|
applyCacheSeconds, cacheForSeconds, check, checkAndPrepare, checkAndPrepare, getCacheSeconds, isRequireSession, preventCaching, setCacheSeconds, setRequireSessiongetPortletContext, getTempDir, isContextRequired, setPortletContextpublic static final String IMPLICIT_MODEL_SESSION_ATTRIBUTE
public static final String IMPLICIT_MODEL_RENDER_PARAMETER
public void setWebBindingInitializer(org.springframework.web.bind.support.WebBindingInitializer webBindingInitializer)
public void setSessionAttributeStore(org.springframework.web.bind.support.SessionAttributeStore sessionAttributeStore)
Default is DefaultSessionAttributeStore,
storing session attributes in the PortletSession, using the same
attribute name as in the model.
public void setCacheSecondsForSessionAttributeHandlers(int cacheSecondsForSessionAttributeHandlers)
@SessionAttributes annotated handlers
for the given number of seconds. Default is 0, preventing caching completely.
In contrast to the "cacheSeconds" property which will apply to all general
handlers (but not to @SessionAttributes annotated handlers), this
setting will apply to @SessionAttributes annotated handlers only.
PortletContentGenerator.setCacheSeconds(int),
SessionAttributespublic void setSynchronizeOnSession(boolean synchronizeOnSession)
More specifically, the execution of each handler method will get synchronized if this flag is "true". The best available session mutex will be used for the synchronization; ideally, this will be a mutex exposed by HttpSessionMutexListener.
The session mutex is guaranteed to be the same object during
the entire lifetime of the session, available under the key defined
by the SESSION_MUTEX_ATTRIBUTE constant. It serves as a
safe reference to synchronize on for locking on the current session.
In many cases, the PortletSession reference itself is a safe mutex as well, since it will always be the same object reference for the same active logical session. However, this is not guaranteed across different servlet containers; the only 100% safe way is a session mutex.
HttpSessionMutexListener,
PortletUtils.getSessionMutex(javax.portlet.PortletSession)public void setParameterNameDiscoverer(org.springframework.core.ParameterNameDiscoverer parameterNameDiscoverer)
Default is a DefaultParameterNameDiscoverer.
public void setCustomArgumentResolver(org.springframework.web.bind.support.WebArgumentResolver argumentResolver)
public void setCustomArgumentResolvers(org.springframework.web.bind.support.WebArgumentResolver[] argumentResolvers)
public void setCustomModelAndViewResolver(org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver customModelAndViewResolver)
public void setCustomModelAndViewResolvers(org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver[] customModelAndViewResolvers)
public void setOrder(int order)
Default value is Integer.MAX_VALUE, meaning that it's non-ordered.
Ordered.getOrder()public int getOrder()
getOrder in interface org.springframework.core.Orderedpublic void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAwarepublic boolean supports(Object handler)
HandlerAdapterA typical implementation:
return (handler instanceof MyHandler);
supports in interface HandlerAdapterhandler - handler object to checkpublic void handleAction(ActionRequest request, ActionResponse response, Object handler) throws Exception
HandlerAdapterhandleAction in interface HandlerAdapterrequest - current action requestresponse - current action responsehandler - handler to use. This object must have previously been passed
to the supports method of this interface, which must have
returned true.Exception - in case of errorsPortlet.processAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse)public ModelAndView handleRender(RenderRequest request, RenderResponse response, Object handler) throws Exception
HandlerAdapterhandleRender in interface HandlerAdapterrequest - current render requestresponse - current render responsehandler - handler to use. This object must have previously been passed
to the supports method of this interface, which must have
returned true.null if the request has been handled directlyException - in case of errorsPortlet.render(javax.portlet.RenderRequest, javax.portlet.RenderResponse)public ModelAndView handleResource(ResourceRequest request, ResourceResponse response, Object handler) throws Exception
HandlerAdapterhandleResource in interface HandlerAdapterrequest - current render requestresponse - current render responsehandler - handler to use. This object must have previously been passed
to the supports method of this interface, which must have
returned true.null if the request has been handled directlyException - in case of errorsResourceServingPortlet.serveResource(javax.portlet.ResourceRequest, javax.portlet.ResourceResponse)public void handleEvent(EventRequest request, EventResponse response, Object handler) throws Exception
HandlerAdapterhandleEvent in interface HandlerAdapterrequest - current action requestresponse - current action responsehandler - handler to use. This object must have previously been passed
to the supports method of this interface, which must have
returned true.Exception - in case of errorsEventPortlet.processEvent(javax.portlet.EventRequest, javax.portlet.EventResponse)protected ModelAndView doHandle(PortletRequest request, PortletResponse response, Object handler) throws Exception
Exceptionprotected PortletRequestDataBinder createBinder(PortletRequest request, Object target, String objectName) throws Exception
The default implementation creates a standard PortletRequestDataBinder. This can be overridden for custom PortletRequestDataBinder subclasses.
request - current portlet requesttarget - the target object to bind onto (or null
if the binder is just used to convert a plain parameter value)objectName - the objectName of the target objectException - in case of invalid state or argumentsPortletRequestDataBinder.bind(javax.portlet.PortletRequest)