站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Spring Framework 2.0.5 API 文档英文版

ParameterMethodNameResolver (Spring Framework API 2.0) - Spring Framework 2.0.5 API 文档英文版

The Spring Framework

org.springframework.web.servlet.mvc.multiaction
Class ParameterMethodNameResolver

java.lang.Object
  extended by org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver
All Implemented Interfaces:
MethodNameResolver

public class ParameterMethodNameResolver
extends Object
implements MethodNameResolver

Implementation of MethodNameResolver which supports several strategies for mapping parameter values to the names of methods to invoke.

The simplest strategy looks for a specific named parameter, whose value is considered the name of the method to invoke. The name of the parameter may be specified as a JavaBean property, if the default action is not acceptable.

The alternative strategy uses the very existence of a request parameter ( i.e. a request parameter with a certain name is found) as an indication that a method with the same name should be dispatched to. In this case, the actual request parameter value is ignored. The list of parameter/method names may be set via the methodParamNames JavaBean property.

The second resolution strategy is primarily expected to be used with web pages containing multiple submit buttons. The 'name' attribute of each button should be set to the mapped method name, while the 'value' attribute is normally displayed as the button label by the browser, and will be ignored by the resolver.

Note that the second strategy also supports the use of submit buttons of type 'image'. That is, an image submit button named 'reset' will normally be submitted by the browser as two request paramters called 'reset.x', and 'reset.y'. When checking for the existence of a paramter from the methodParamNames list, to indicate that a specific method should be called, the code will look for request parameter in the "reset" form (exactly as spcified in the list), and in the "reset.x" form ('.x' appended to the name in the list). In this way it can handle both normal and image submit buttons. The actual method name resolved if there is a match will always be the bare form without the ".x".

Note: If both strategies are configured, i.e. both "paramName" and "methodParamNames" are specified, then both will be checked for any given request. A match for an explicit request parameter in the "methodParamNames" list always wins over a value specified for a "paramName" action parameter.

For use with either strategy, the name of a default handler method to use when there is no match, can be specified as a JavaBean property.

For both resolution strategies, the method name is of course coming from some sort of view code, (such as a JSP page). While this may be acceptable, it is sometimes desireable to treat this only as a 'logical' method name, with a further mapping to a 'real' method name. As such, an optional 'logical' mapping may be specified for this purpose.

Author:
Rod Johnson, Juergen Hoeller, Colin Sampaleanu
See Also:
setParamName(java.lang.String), setMethodParamNames(java.lang.String[]), setLogicalMappings(java.util.Properties), setDefaultMethodName(java.lang.String)

Field Summary
static String DEFAULT_PARAM_NAME
          Default name for the parameter whose value identifies the method to invoke: "action".
protected  Log logger
           
 
Constructor Summary
ParameterMethodNameResolver()
           
 
Method Summary
 String getHandlerMethodName(HttpServletRequest request)
          Return a method name that can handle this request.
 void setDefaultMethodName(String defaultMethodName)
          Set the name of the default handler method that should be used when no parameter was found in the request
 void setLogicalMappings(Properties logicalMappings)
          Specifies a set of optional logical method name mappings.
 void setMethodParamNames(String[] methodParamNames)
          Set a String array of parameter names, where the very existence of a parameter in the list (with value ignored) means that a method of the same name should be invoked.
 void setParamName(String paramName)
          Set the name of the parameter whose value identifies the name of the method to invoke.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PARAM_NAME

public static final String DEFAULT_PARAM_NAME
Default name for the parameter whose value identifies the method to invoke: "action".

See Also:
Constant Field Values

logger

protected final Log logger
Constructor Detail

ParameterMethodNameResolver

public ParameterMethodNameResolver()
Method Detail

setParamName

public void setParamName(String paramName)
Set the name of the parameter whose value identifies the name of the method to invoke. Default is "action".

Alternatively, specify parameter names where the very existence of each parameter means that a method of the same name should be invoked, via the "methodParamNames" property.

See Also:
setMethodParamNames(java.lang.String[])

setMethodParamNames

public void setMethodParamNames(String[] methodParamNames)
Set a String array of parameter names, where the very existence of a parameter in the list (with value ignored) means that a method of the same name should be invoked. This target method name may then be optionally further mapped via the logicalMappings property, in which case it can be considered a logical name only.

See Also:
setParamName(java.lang.String)

setLogicalMappings

public void setLogicalMappings(Properties logicalMappings)
Specifies a set of optional logical method name mappings. For both resolution strategies, the method name initially comes in from the view layer. If that needs to be treated as a 'logical' method name, and mapped to a 'real' method name, then a name/value pair for that purpose should be added to this Properties instance. Any method name not found in this mapping will be considered to already be the real method name.

Note that in the case of no match, where the defaultMethodName property is used if available, that method name is considered to already be the real method name, and is not run through the logical mapping.

Parameters:
logicalMappings - a Properties object mapping logical method names to real method names

setDefaultMethodName

public void setDefaultMethodName(String defaultMethodName)
Set the name of the default handler method that should be used when no parameter was found in the request


getHandlerMethodName

public String getHandlerMethodName(HttpServletRequest request)
                            throws NoSuchRequestHandlingMethodException
Description copied from interface: MethodNameResolver
Return a method name that can handle this request. Such mappings are typically, but not necessarily, based on URL.

Specified by:
getHandlerMethodName in interface MethodNameResolver
Parameters:
request - current HTTP request
Returns:
a method name that can handle this request. Never returns null; throws exception if not resolvable.
Throws:
NoSuchRequestHandlingMethodException - if no handler method can be found for the given request

The Spring Framework

Copyright © 2002-2007 The Spring Framework.