@DefaultKey(value="params") @ValidScope(value="request") public class ParameterTool extends ValueParser
Utility class for easy parsing of ServletRequest
parameters.
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.
ALLOWSUBKEYS_KEY, DEFAULT_STRINGS_DELIMITER, READONLY_KEY, STRINGS_DELIMITER_FORMAT_KEY
DEFAULT_FORMAT, FORMAT_KEY
DEFAULT_LOCALE
LOCK_CONFIG_KEY, log, LOGGER_NAME_KEY, SAFE_MODE_KEY, USE_CLASS_LOGGER_KEY
Constructor and Description |
---|
ParameterTool()
Constructs a new instance
|
ParameterTool(javax.servlet.ServletRequest request)
Constructs a new instance using the specified request.
|
Modifier and Type | Method and Description |
---|---|
protected void |
configure(ValueParser values)
Does the actual configuration.
|
Map |
getAll() |
protected javax.servlet.ServletRequest |
getRequest()
Returns the current
ServletRequest for this instance. |
protected Map |
getSource()
Overrides ValueParser.getSource() to return the result
of getRequest().getParameterMap() and expand singleton
arrays within it first.
|
Object |
getValue(String key)
Overrides ValueParser.getValue(String key) to retrieve the
value from the ServletRequest instead of an arbitrary Map.
|
Object[] |
getValues(String key)
Overrides ValueParser.getValues(String key) to retrieve
Strings from the ServletRequest instead of an arbitrary Map.
|
void |
setRequest(javax.servlet.ServletRequest request)
Sets the current
ServletRequest |
protected void |
setSource(Map source)
Overrides ValueParser.setSource(Map source) to throw an
UnsupportedOperationException, because this class uses
a servlet request as its source, not a Map.
|
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
getFormat, setFormat
getLocale, setLocale, toLocale
configure, getLog, initLogger, isConfigLocked, isSafeMode, setLockConfig, setSafeMode
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
public ParameterTool()
public ParameterTool(javax.servlet.ServletRequest request)
request
- the ServletRequest
to be parsedprotected void configure(ValueParser values)
ValueParser
configure
in class ValueParser
values
- configuration valuespublic void setRequest(javax.servlet.ServletRequest request)
ServletRequest
request
- the ServletRequest
to be parsedprotected javax.servlet.ServletRequest getRequest()
ServletRequest
for this instance.ServletRequest
UnsupportedOperationException
- if the request is nullpublic Object getValue(String key)
getValue
in class ValueParser
key
- the parameter's keynull
if there is no matching
parameterpublic Object[] getValues(String key)
getValues
in class ValueParser
key
- the key for the desired parameternull
if the parameter does not existprotected void setSource(Map source)
setSource
in class ValueParser
protected Map getSource()
getSource
in class ValueParser
public Map getAll()
Copyright © 2002–2021 The Apache Software Foundation. All rights reserved.