public class PortletModeParameterHandlerMapping extends AbstractMapBasedHandlerMapping<com.liferay.portletmvc4spring.handler.PortletModeParameterLookupKey>
HandlerMapping
interface to map from the current
PortletMode and a request parameter to request handler beans. The mapping consists of two levels: first the
PortletMode and then the parameter value. In order to be mapped, both elements must match the mapping definition.
This is a combination of the methods used in PortletModeHandlerMapping
and
ParameterHandlerMapping
. Unlike those two classes, this mapping cannot be initialized
with properties since it requires a two-level map.
The default name of the parameter is "action", but can be changed using setParameterName()
.
By default, the same parameter value may not be used in two different portlet modes. This is so that if the portal itself changes the portlet mode, the request will no longer be valid in the mapping.
The bean configuration for this mapping will look somthing like this:
<bean id="portletModeParameterHandlerMapping" class="com.liferay.portletmvc4spring.handler.PortletModeParameterHandlerMapping"> <property name="portletModeParameterMap"> <map> <entry key="view"> <!-- portlet mode: view --> <map> <entry key="add"><ref bean="addItemHandler"/></entry> <entry key="edit"><ref bean="editItemHandler"/></entry> <entry key="delete"><ref bean="deleteItemHandler"/></entry> </map> </entry> <entry key="edit"> <!-- portlet mode: edit --> <map> <entry key="prefs"><ref bean="preferencesHandler"/></entry> <entry key="resetPrefs"><ref bean="resetPreferencesHandler"/></entry> </map> </entry> </map> </property> </bean>
This mapping can be chained ahead of a PortletModeHandlerMapping
, which can then
provide defaults for each mode and an overall default as well.
Thanks to Rainer Schmitz and Yujin Kim for suggesting this mapping strategy!
ParameterMappingInterceptor
AbstractMapBasedHandlerMapping.PortletRequestMappingPredicate
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_PARAMETER_NAME
Default request parameter name to use for mapping to handlers: "action".
|
logger
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor and Description |
---|
PortletModeParameterHandlerMapping() |
Modifier and Type | Method and Description |
---|---|
protected com.liferay.portletmvc4spring.handler.PortletModeParameterLookupKey |
getLookupKey(javax.portlet.PortletRequest request)
Returns a lookup key that combines the current PortletMode and the current value of the specified parameter.
|
void |
initApplicationContext()
Calls the
registerHandlers method in addition to the superclass's initialization. |
protected void |
registerHandler(javax.portlet.PortletMode mode,
Map<String,?> parameterMap)
Register all handlers specified in the given parameter map.
|
protected void |
registerHandler(javax.portlet.PortletMode mode,
String parameter,
Object handler)
Register the given handler instance for the given PortletMode and parameter value, under an appropriate lookup
key.
|
protected void |
registerHandlersByModeAndParameter(Map<String,Map<String,?>> portletModeParameterMap)
Register all handlers specified in the Portlet mode map for the corresponding modes.
|
void |
setAllowDuplicateParameters(boolean allowDuplicateParameters)
Set whether to allow duplicate parameter values across different portlet modes.
|
void |
setParameterName(String parameterName)
Set the name of the parameter used for mapping to handlers.
|
void |
setPortletModeParameterMap(Map<String,Map<String,?>> portletModeParameterMap)
Set a Map with portlet mode names as keys and another Map as values.
|
getHandlerInternal, registerHandler, registerHandler, registerHandlers, setLazyInitHandlers
adaptInterceptor, extendInterceptors, getAdaptedInterceptors, getDefaultHandler, getHandler, getHandlerExecutionChain, getOrder, initInterceptors, setApplyWebRequestInterceptorsToRenderPhaseOnly, setDefaultHandler, setInterceptors, setOrder
getApplicationContext, getMessageSourceAccessor, initApplicationContext, isContextRequired, obtainApplicationContext, requiredContextClass, setApplicationContext
public static final String DEFAULT_PARAMETER_NAME
public void initApplicationContext() throws BeansException
registerHandlers
method in addition to the superclass's initialization.initApplicationContext
in class AbstractHandlerMapping
BeansException
AbstractMapBasedHandlerMapping.registerHandlers(java.util.Map<K, ?>)
public void setAllowDuplicateParameters(boolean allowDuplicateParameters)
Doing this is dangerous because the portlet mode can be changed by the portal itself and the only way to see that is a rerender of the portlet. If the same parameter value is legal in multiple modes, then a change in mode could result in a matched mapping that is not intended and the user could end up in a strange place in the application.
public void setParameterName(String parameterName)
Default is "action".
public void setPortletModeParameterMap(Map<String,Map<String,?>> portletModeParameterMap)
Convenient for population with bean references.
portletModeParameterMap
- two-level map of portlet modes and parameters to handler beansprotected com.liferay.portletmvc4spring.handler.PortletModeParameterLookupKey getLookupKey(javax.portlet.PortletRequest request) throws Exception
getLookupKey
in class AbstractMapBasedHandlerMapping<com.liferay.portletmvc4spring.handler.PortletModeParameterLookupKey>
request
- current portlet requestnull
)Exception
- if key computation failedRenderState.getPortletMode()
,
setParameterName(java.lang.String)
protected void registerHandler(javax.portlet.PortletMode mode, Map<String,?> parameterMap)
parameterMap
- Map with parameter names as keys and handler beans or bean names as valuesprotected void registerHandler(javax.portlet.PortletMode mode, String parameter, Object handler) throws BeansException, IllegalStateException
mode
- the PortletMode for which this mapping is validparameter
- the parameter value to which this handler is mappedhandler
- the handler instance beanBeansException
- if the handler couldn't be registeredIllegalStateException
- if there is a conflicting handler registeredAbstractMapBasedHandlerMapping.registerHandler(Object, Object)
protected void registerHandlersByModeAndParameter(Map<String,Map<String,?>> portletModeParameterMap)
portletModeParameterMap
- Map with mode names as keys and parameter Maps as valuesCopyright © 2019 Liferay, Inc.. All rights reserved.