Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| The Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.springframework.web.portlet.handler
Class PortletModeParameterHandlerMapping

    java.lang.Object
      org.springframework.context.support.ApplicationObjectSupport
          org.springframework.web.portlet.handler.AbstractHandlerMapping
              org.springframework.web.portlet.handler.AbstractMapBasedHandlerMapping
                  org.springframework.web.portlet.handler.PortletModeParameterHandlerMapping

All Implemented Interfaces:
  ApplicationContextAware, Ordered, HandlerMapping

    public class PortletModeParameterHandlerMapping

extends AbstractMapBasedHandlerMapping

Implementation of the `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. This behavior can be changed with `setAllowDupParameters()`.

The bean configuration for this mapping will look somthing like this:

     <bean id="portletModeParameterHandlerMapping" class="org.springframework.web.portlet.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!

Since:
  2.0
Author:
  John A. Lewis, Juergen Hoeller
See Also:
  `ParameterMappingInterceptor`

Nested Class Summary

Nested classes/interfaces inherited from class org.springframework.web.portlet.handler.AbstractMapBasedHandlerMapping
`AbstractMapBasedHandlerMapping.PortletRequestMappingPredicate`

Field Summary
`static String` | `DEFAULT_PARAMETER_NAME` Default request parameter name to use for mapping to handlers: "action".

Fields inherited from class org.springframework.context.support.ApplicationObjectSupport
`logger`

Fields inherited from interface org.springframework.core.Ordered
`HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE`

Constructor Summary
`PortletModeParameterHandlerMapping()`

Method Summary
`protected Object` | `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 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` | `registerHandlers(Map 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 portletModeParameterMap)` Set a Map with portlet mode names as keys and another Map as values.

Methods inherited from class org.springframework.web.portlet.handler.AbstractMapBasedHandlerMapping
`getHandlerInternal, registerHandler, registerHandler, setLazyInitHandlers`

Methods inherited from class org.springframework.web.portlet.handler.AbstractHandlerMapping
`adaptInterceptor, extendInterceptors, getAdaptedInterceptors, getDefaultHandler, getHandler, getHandlerExecutionChain, getOrder, initInterceptors, setApplyWebRequestInterceptorsToRenderPhaseOnly, setDefaultHandler, setInterceptors, setOrder`

Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
`getApplicationContext, getMessageSourceAccessor, initApplicationContext, isContextRequired, requiredContextClass, setApplicationContext`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### DEFAULT_PARAMETER_NAME

    public static final String DEFAULT_PARAMETER_NAME

  Default request parameter name to use for mapping to handlers: "action".

  See Also:
    Constant Field Values

Constructor Detail

### PortletModeParameterHandlerMapping

    public PortletModeParameterHandlerMapping()

Method Detail

### setParameterName

    public void setParameterName(String parameterName)

  Set the name of the parameter used for mapping to handlers.

  Default is "action".

### setPortletModeParameterMap

    public void setPortletModeParameterMap(Map portletModeParameterMap)

  Set a Map with portlet mode names as keys and another Map as values. The sub-map has parameter names as keys and handler bean or bean names as values.

  Convenient for population with bean references.

  Parameters:
    `portletModeParameterMap` - two-level map of portlet modes and parameters to handler beans

### setAllowDuplicateParameters

    public void setAllowDuplicateParameters(boolean allowDuplicateParameters)

  Set whether to allow duplicate parameter values across different portlet modes. Default is "false".

  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.

### initApplicationContext

    public void initApplicationContext()
                                throws BeansException

  Calls the `registerHandlers` method in addition to the superclass's initialization.

  Overrides:
    `initApplicationContext` in class `AbstractHandlerMapping`
  Throws:
    `ApplicationContextException` - in case of initialization errors
    `BeansException` - if thrown by ApplicationContext methods
  See Also:
    `registerHandlers(java.util.Map)`

### registerHandlers

    protected void registerHandlers(Map portletModeParameterMap)
                             throws BeansException

  Register all handlers specified in the Portlet mode map for the corresponding modes.

  Overrides:
    `registerHandlers` in class `AbstractMapBasedHandlerMapping`
  Parameters:
    `portletModeParameterMap` - Map with mode names as keys and parameter Maps as values
  Throws:
    `BeansException` - if the handler couldn't be registered

### registerHandler

    protected void registerHandler(javax.portlet.PortletMode mode,
                                   Map parameterMap)
                            throws BeansException

  Register all handlers specified in the given parameter map.

  Parameters:
    `parameterMap` - Map with parameter names as keys and handler beans or bean names as values
  Throws:
    `BeansException` - if the handler couldn't be registered

### registerHandler

    protected void registerHandler(javax.portlet.PortletMode mode,
                                   String parameter,
                                   Object handler)
                            throws BeansException,
                                   IllegalStateException

  Register the given handler instance for the given PortletMode and parameter value, under an appropriate lookup key.

  Parameters:
    `mode` - the PortletMode for which this mapping is valid
    `parameter` - the parameter value to which this handler is mapped
    `handler` - the handler instance bean
  Throws:
    `BeansException` - if the handler couldn't be registered
    `IllegalStateException` - if there is a conflicting handler registered
  See Also:
    `AbstractMapBasedHandlerMapping.registerHandler(Object, Object)`

### getLookupKey

    protected Object getLookupKey(javax.portlet.PortletRequest request)
                           throws Exception

  Returns a lookup key that combines the current PortletMode and the current value of the specified parameter.

  Specified by:
    `getLookupKey` in class `AbstractMapBasedHandlerMapping`
  Parameters:
    `request` - current portlet request
  Returns:
    the lookup key (never `null`)
  Throws:
    `Exception` - if key computation failed
  See Also:
    `PortletRequest.getPortletMode()`, `setParameterName(java.lang.String)`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| The Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2002-2008 The Spring Framework.