Package org.apache.velocity.tools.view
Class ParameterTool
- java.lang.Object
-
- org.apache.velocity.tools.generic.SafeConfig
-
- org.apache.velocity.tools.generic.LocaleConfig
-
- org.apache.velocity.tools.generic.FormatConfig
-
- org.apache.velocity.tools.generic.ValueParser
-
- org.apache.velocity.tools.view.ParameterTool
-
- All Implemented Interfaces:
java.util.Map<java.lang.String,java.lang.Object>
@DefaultKey("params") @ValidScope("request") public class ParameterTool extends org.apache.velocity.tools.generic.ValueParserUtility class for easy parsing of
ServletRequestparameters.Template example(s): $params.foo -> bar $params.getNumber('baz') -> 12.6 $params.getInt('baz') -> 12 $params.getNumbers('baz') -> [12.6] Toolbox configuration: <tools> <toolbox scope="request"> <tool class="org.apache.velocity.tools.view.ParameterTool"/> </toolbox> </tools>When used as a view tool, this should only be used in the request scope. This class is, however, quite useful in your application's controller, filter, or action code as well as in templates.
- Since:
- VelocityTools 2.0
- Version:
- $Revision$ $Date$
- Author:
- Nathan Bubna
-
-
Constructor Summary
Constructors Constructor Description ParameterTool()Constructs a new instanceParameterTool(javax.servlet.ServletRequest request)Constructs a new instance using the specified request.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidconfigure(org.apache.velocity.tools.generic.ValueParser values)java.util.MapgetAll()protected javax.servlet.ServletRequestgetRequest()Returns the currentServletRequestfor this instance.protected java.util.MapgetSource()Overrides ValueParser.getSource() to return the result of getRequest().getParameterMap() and expand singleton arrays within it first.java.lang.ObjectgetValue(java.lang.String key)Overrides ValueParser.getValue(String key) to retrieve the value from the ServletRequest instead of an arbitrary Map.java.lang.Object[]getValues(java.lang.String key)Overrides ValueParser.getValues(String key) to retrieve Strings from the ServletRequest instead of an arbitrary Map.voidsetRequest(javax.servlet.ServletRequest request)Sets the currentServletRequestprotected voidsetSource(java.util.Map source)Overrides ValueParser.setSource(Map source) to throw an UnsupportedOperationException, because this class uses a servlet request as its source, not a Map.-
Methods inherited from class org.apache.velocity.tools.generic.ValueParser
clear, containsKey, containsValue, entrySet, exists, get, get, getAllowSubkeys, getBoolean, getBoolean, getBoolean, getBooleans, getDouble, getDouble, getDouble, getDoubles, getInt, getInteger, getInteger, getInts, getLocale, getLocale, getLocales, getLong, getLong, getNumber, getNumber, getNumbers, getReadOnly, getSource, getString, getString, getStrings, getSubkey, getSubkeys, getValue, hasSubkeys, isEmpty, keySet, parseStringList, put, putAll, remove, setAllowSubkeys, setReadOnly, setStringsDelimiter, size, toString, values
-
Methods inherited from class org.apache.velocity.tools.generic.LocaleConfig
getLocale, setLocale, toLocale
-
Methods inherited from class org.apache.velocity.tools.generic.SafeConfig
configure, getLog, initLogger, isConfigLocked, isSafeMode, setLockConfig, setSafeMode
-
-
-
-
Method Detail
-
configure
protected void configure(org.apache.velocity.tools.generic.ValueParser values)
- Overrides:
configurein classorg.apache.velocity.tools.generic.ValueParser
-
setRequest
public void setRequest(javax.servlet.ServletRequest request)
Sets the currentServletRequest- Parameters:
request- theServletRequestto be parsed
-
getRequest
protected javax.servlet.ServletRequest getRequest()
Returns the currentServletRequestfor this instance.- Returns:
- the current
ServletRequest - Throws:
java.lang.UnsupportedOperationException- if the request is null
-
getValue
public java.lang.Object getValue(java.lang.String key)
Overrides ValueParser.getValue(String key) to retrieve the value from the ServletRequest instead of an arbitrary Map.- Overrides:
getValuein classorg.apache.velocity.tools.generic.ValueParser- Parameters:
key- the parameter's key- Returns:
- parameter matching the specified key or
nullif there is no matching parameter
-
getValues
public java.lang.Object[] getValues(java.lang.String key)
Overrides ValueParser.getValues(String key) to retrieve Strings from the ServletRequest instead of an arbitrary Map.- Overrides:
getValuesin classorg.apache.velocity.tools.generic.ValueParser- Parameters:
key- the key for the desired parameter- Returns:
- an array of String objects containing all of the values
the given request parameter has, or
nullif the parameter does not exist
-
setSource
protected void setSource(java.util.Map source)
Overrides ValueParser.setSource(Map source) to throw an UnsupportedOperationException, because this class uses a servlet request as its source, not a Map.- Overrides:
setSourcein classorg.apache.velocity.tools.generic.ValueParser
-
getSource
protected java.util.Map getSource()
Overrides ValueParser.getSource() to return the result of getRequest().getParameterMap() and expand singleton arrays within it first.- Overrides:
getSourcein classorg.apache.velocity.tools.generic.ValueParser
-
getAll
public java.util.Map getAll()
- Returns:
- the map of all parameters available for the current request.
-
-