@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_KEYDEFAULT_FORMAT, FORMAT_KEYDEFAULT_LOCALELOCK_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) |
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, valuesgetFormat, setFormatgetLocale, setLocale, toLocaleconfigure, getLog, initLogger, isConfigLocked, isSafeMode, setLockConfig, setSafeModeclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitcompute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAllpublic ParameterTool()
public ParameterTool(javax.servlet.ServletRequest request)
request - the ServletRequest to be parsedprotected void configure(ValueParser values)
configure in class ValueParserpublic void setRequest(javax.servlet.ServletRequest request)
ServletRequestrequest - the ServletRequest to be parsedprotected javax.servlet.ServletRequest getRequest()
ServletRequest for this instance.ServletRequestUnsupportedOperationException - if the request is nullpublic Object getValue(String key)
getValue in class ValueParserkey - the parameter's keynull if there is no matching
parameterpublic Object[] getValues(String key)
getValues in class ValueParserkey - the key for the desired parameternull
if the parameter does not existprotected void setSource(Map source)
setSource in class ValueParserprotected Map getSource()
getSource in class ValueParserpublic Map getAll()
Copyright © 2002–2021 The Apache Software Foundation. All rights reserved.