类 ParameterTool

所有已实现的接口:
Map<String,Object>
直接已知子类:
ParameterParser

@DefaultKey("params") @ValidScope("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.

从以下版本开始:
VelocityTools 2.0
版本:
$Revision: 749733 $ $Date: 2009-03-03 12:24:17 -0800 (Tue, 03 Mar 2009) $
作者:
Nathan Bubna
  • 字段详细资料

    • request

      private ServletRequest request
  • 构造器详细资料

    • ParameterTool

      public ParameterTool()
      Constructs a new instance
    • ParameterTool

      public ParameterTool(ServletRequest request)
      Constructs a new instance using the specified request.
      参数:
      request - the ServletRequest to be parsed
  • 方法详细资料

    • configure

      protected void configure(ValueParser values)
      从类复制的说明: ValueParser
      Does the actual configuration. This is protected, so subclasses may share the same ValueParser and call configure at any time, while preventing templates from doing so when configure(Map) is locked.
      覆盖:
      configure 在类中 ValueParser
    • setRequest

      public void setRequest(ServletRequest request)
      Sets the current ServletRequest
      参数:
      request - the ServletRequest to be parsed
    • getRequest

      protected ServletRequest getRequest()
      Returns the current ServletRequest for this instance.
      返回:
      the current ServletRequest
      抛出:
      UnsupportedOperationException - if the request is null
    • getValue

      public Object getValue(String key)
      Overrides ValueParser.getValue(String key) to retrieve the value from the ServletRequest instead of an arbitrary Map.
      覆盖:
      getValue 在类中 ValueParser
      参数:
      key - the parameter's key
      返回:
      parameter matching the specified key or null if there is no matching parameter
    • getValues

      public Object[] getValues(String key)
      Overrides ValueParser.getValues(String key) to retrieve Strings from the ServletRequest instead of an arbitrary Map.
      覆盖:
      getValues 在类中 ValueParser
      参数:
      key - the key for the desired parameter
      返回:
      an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist
    • setSource

      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.
      覆盖:
      setSource 在类中 ValueParser
    • getSource

      protected Map getSource()
      Overrides ValueParser.getSource() to return the result of getRequest().getParameterMap() and expand singleton arrays within it first.
      覆盖:
      getSource 在类中 ValueParser
    • getAll

      public Map getAll()
      Returns the map of all parameters available for the current request.
    • isSingletonArray

      private boolean isSingletonArray(Object value)
    • expandSingletonArrays

      private Map<String,Object> expandSingletonArrays(Map<String,String[]> original)