类 FormTool

java.lang.Object
org.apache.velocity.tools.struts.FormTool

@DefaultKey("form") @ValidScope("request") public class FormTool extends Object

View tool to work with HTML forms in Struts.

Struts has support to parse incoming HTTP requests and populate a Java bean with the submitted request parameters. The same Java bean is used to populate forms with initial values. Additionally, a hook allows the application developer to include automatic form validation code.

FormTool provides miscellaneous methods to work with forms and form bean in the context of Struts applications.

 Template example(s):
  <input type="hidden" name="$form.tokenName" value="$form.token">
  <input type="submit" name="$form.cancelName" value="Cancel">

 Toolbox configuration:
 <tools>
   <toolbox scope="request">
     <tool class="org.apache.velocity.tools.struts.FormTool"/>
   </toolbox>
 </tools>
 

This tool may only be used in the request scope.

从以下版本开始:
VelocityTools 1.0
版本:
$Id: FormTool.java 601976 2007-12-07 03:50:51Z nbubna $
作者:
Gabe Sidler
  • 字段概要

    字段
    修饰符和类型
    字段
    说明
    protected HttpServletRequest
    A reference to the HtttpServletRequest.
    protected HttpSession
    A reference to the HtttpSession.
  • 构造器概要

    构造器
    构造器
    说明
     
  • 方法概要

    修饰符和类型
    方法
    说明
    ActionForm
    Returns the form bean associated with this action mapping.
    Returns the query parameter name under which a cancel button press must be reported if form validation is to be skipped.
    Returns the form bean name associated with this action mapping.
    Returns the transaction control token for this session or null if no token exists.
    Returns the query parameter name under which a transaction token must be reported.
    void
    init(Object obj)
    已过时。
    void
    setRequest(HttpServletRequest request)
    Initializes this tool.

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 字段详细资料

    • request

      protected HttpServletRequest request
      A reference to the HtttpServletRequest.
    • session

      protected HttpSession session
      A reference to the HtttpSession.
  • 构造器详细资料

    • FormTool

      public FormTool()
  • 方法详细资料

    • init

      @Deprecated public void init(Object obj)
      已过时。
    • setRequest

      public void setRequest(HttpServletRequest request)
      Initializes this tool.
      参数:
      request - the current HttpServletRequest
      抛出:
      IllegalArgumentException - if the param is not a ViewContext
    • getBean

      public ActionForm getBean()

      Returns the form bean associated with this action mapping.

      This is a convenience method. The form bean is automatically available in the Velocity context under the name defined in the Struts configuration.

      If the form bean is used repeatedly, it is recommended to create a local variable referencing the bean rather than calling getBean() multiple times.

       Example:
       #set ($defaults = $form.bean)
       <input type="text" name="username" value="$defaults.username">
       
      返回:
      the ActionForm associated with this request or null if there is no form bean associated with this mapping
    • getName

      public String getName()

      Returns the form bean name associated with this action mapping.

      返回:
      the name of the ActionForm associated with this request or null if there is no form bean associated with this mapping
    • getCancelName

      public String getCancelName()

      Returns the query parameter name under which a cancel button press must be reported if form validation is to be skipped.

      This is the value of org.apache.struts.taglib.html.Constants.CANCEL_PROPERTY

    • getToken

      public String getToken()
      Returns the transaction control token for this session or null if no token exists.
    • getTokenName

      public String getTokenName()

      Returns the query parameter name under which a transaction token must be reported. This is the value of org.apache.struts.taglib.html.Constants.TOKEN_KEY