org.apache.velocity.tools.struts
Class FormTool

java.lang.Object
  |
  +--org.apache.velocity.tools.struts.FormTool
All Implemented Interfaces:
ViewTool

public class FormTool
extends java.lang.Object
implements ViewTool

View tool to work with HTML forms in Struts.

This class is equipped to be used with a toolbox manager, for example the ServletToolboxManager included with VelServlet. This class implements interface ViewTool, which allows a toolbox manager to pass the required context information.

This class is not thread-safe by design. A new instance is needed for the processing of every template request. This means this tool should only be used in the request scope, not application or session scopes.

Version:
$Id: FormTool.java,v 1.3 2003/05/28 00:17:15 nbubna Exp $
Author:
Gabe Sidler

Field Summary
protected  javax.servlet.http.HttpServletRequest request
          A reference to the HtttpServletRequest.
protected  javax.servlet.http.HttpSession session
          A reference to the HtttpSession.
 
Constructor Summary
FormTool()
          Default constructor.
 
Method Summary
 org.apache.struts.action.ActionForm getBean()
          Returns the form bean associated with this action mapping.
 java.lang.String getCancelName()
          Returns the query parameter name under which a cancel button press must be reported if form validation is to be skipped.
 java.lang.String getToken()
          Returns the transaction control token for this session or null if no token exists.
 java.lang.String getTokenName()
          Returns the query parameter name under which a transaction token must be reported.
 void init(java.lang.Object obj)
          Initializes this tool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

request

protected javax.servlet.http.HttpServletRequest request
A reference to the HtttpServletRequest.


session

protected javax.servlet.http.HttpSession session
A reference to the HtttpSession.

Constructor Detail

FormTool

public FormTool()
Default constructor. Tool must be initialized before use.

Method Detail

init

public void init(java.lang.Object obj)
Initializes this tool.

Specified by:
init in interface ViewTool
Parameters:
obj - the current ViewContext
Throws:
java.lang.IllegalArgumentException - if the param is not a ViewContext

getBean

public org.apache.struts.action.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">
 

Returns:
the ActionForm associated with this request or null if there is no form bean associated with this mapping

getCancelName

public java.lang.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 java.lang.String getToken()
Returns the transaction control token for this session or null if no token exists.


getTokenName

public java.lang.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



Copyright (c) 2003 Apache Software Foundation