com.samskivert.velocity
Class FormTool

java.lang.Object
  extended by com.samskivert.velocity.FormTool

public class FormTool
extends Object

The form tool can be placed into an invocation context and used by the template to create form elements which automatically inherit form values which were provided to the page at request time. For example:

 Please enter your name: $form.text("name", 40) $form.submit("submit")
 
If the servlet was invoked with a value for "name", it will be automatically filled into the "name" form field when it is requested.


Field Summary
protected  javax.servlet.http.HttpServletRequest _req
          A reference to the servlet request in use by this form tool.
protected  boolean _useXHTML
          Whether or not we should aim to generate XHTML or HTML.
 
Constructor Summary
FormTool(javax.servlet.http.HttpServletRequest req)
          Constructs a form tool that will use the supplied HTTP servlet request object to prefetch form values.
 
Method Summary
 String action(String value)
          Generates a hidden form field named action with the specified value.
 String button(String name, String text, String extra)
          Constructs a button input element with the specified parameter name, the specified button text, and the specified extra text.
 String checkbox(String name, boolean defaultValue)
          Constructs a checkbox input field with the specified name and default value.
 String fixedCheckbox(String name, boolean value)
          Constructs a checkbox input field with the specified name and value.
 String fixedHidden(String name, Object value)
          Constructs a fixed hidden element with the specified parameter name and value.
protected  String fixedInput(String type, String name, Object value, String extra)
          Generates an input form field with the specified type, name, value and extra attributes.
 String fixedOption(String name, String value, String item, Object selectedValue)
          Constructs an option entry for a select menu with the specified name, value, item, and selected value.
 String fixedText(String name, String extra, Object value)
          Creates a text input field with the specified name and the specified extra arguments and the specified value.
 String fixedTextarea(String name, String extra, Object value)
          Construct a text area with the specified name, optional extra parameters and the specified text.
protected  String getCloseBrace()
          Returns the string used to close unmatched tags.
protected  String getParameter(String name)
          Returns value of the specified query parameter or null if it is not set.
protected  String getValue(String name, Object defaultValue)
          Fetches the requested value from the servlet request and entifies it appropriately.
 String hidden(String name)
          Constructs a hidden element with the specified parameter name where the value is extracted from the appropriate request parameter.
 String hidden(String name, Object defaultValue)
          Constructs a hidden element with the specified parameter name where the value is extracted from the appropriate request parameter unless there is no value in which case the supplied default value is used.
 String imageSubmit(String name, String imagePath)
          Constructs a image submit element with the specified parameter name and image path.
 String imageSubmit(String name, String value, String imagePath)
          Constructs a image submit element with the specified parameter name and image path.
 String imageSubmit(String name, String value, String imagePath, String altText)
          Constructs a image submit element with the specified parameter name and image path.
protected  String input(String type, String name, String extra, Object defaultValue)
          Generates an input form field with the specified type, name, defaultValue and extra attributes.
 String option(String name, String value, String item, Object defaultValue)
          Constructs an option entry for a select menu with the specified name, value, item, and default selected value.
 String password(String name)
          Creates a password input field with the specified name and no extra arguments or default value.
 String password(String name, String extra)
          Creates a password input field with the specified name and the specified extra arguments with no default value.
 String password(String name, String extra, Object defaultValue)
          Creates a password input field with the specified name, extra arguments and default value.
 String radio(String name, String value)
          Creates a radio button with the specified name and value.
 String radio(String name, String value, String defaultValue)
          Creates a radio button with the specified name and value.
 String reset(String name, String value)
          Creates a reset form element.
 void setUseXHTML(boolean useXHTML)
          Used to deactivate XHTML generation for "old skool" Java HTML viewer.
 String submit(String text)
          Constructs a submit element with the name submit and the specified button text.
 String submit(String name, String text)
          Constructs a submit element with the specified parameter name and the specified button text.
 String submitExtra(String text, String extra)
          Constructs a submit element with the name submit and the specified button text with the specified extra text.
 String submitExtra(String name, String text, String extra)
          Constructs a submit element with the specified parameter name and the specified button text with the specified extra text.
 String text(String name)
          Creates a text input field with the specified name and no extra arguments or default value.
 String text(String name, String extra)
          Creates a text input field with the specified name and the specified extra arguments with no default value.
 String text(String name, String extra, Object defaultValue)
          Creates a text input field with the specified name, extra arguments and default value.
 String textarea(String name, String extra, Object defaultValue)
          Constructs a text area with the specified name, optional extra parameters, and default text.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_req

protected javax.servlet.http.HttpServletRequest _req
A reference to the servlet request in use by this form tool.


_useXHTML

protected boolean _useXHTML
Whether or not we should aim to generate XHTML or HTML.

Constructor Detail

FormTool

public FormTool(javax.servlet.http.HttpServletRequest req)
Constructs a form tool that will use the supplied HTTP servlet request object to prefetch form values.

Method Detail

setUseXHTML

public void setUseXHTML(boolean useXHTML)
Used to deactivate XHTML generation for "old skool" Java HTML viewer.


text

public String text(String name)
Creates a text input field with the specified name and no extra arguments or default value.

See Also:
text(String,String,Object)

text

public String text(String name,
                   String extra)
Creates a text input field with the specified name and the specified extra arguments with no default value.

See Also:
text(String,String,Object)

text

public String text(String name,
                   String extra,
                   Object defaultValue)
Creates a text input field with the specified name, extra arguments and default value. For example, a call to text("foo", "size=\"5\" maxLength=\"8\"", "bar") would result in an input field looking like:
 <input type="text" name="foo" value="bar" size="5" maxLength="8"/>
 
Assuming the foo parameter had no pre-existing value.


fixedText

public String fixedText(String name,
                        String extra,
                        Object value)
Creates a text input field with the specified name and the specified extra arguments and the specified value.


reset

public String reset(String name,
                    String value)
Creates a reset form element.

Parameters:
name - the name of the form element (used by JavaScript).
value - the name that will appear on the button.

password

public String password(String name)
Creates a password input field with the specified name and no extra arguments or default value.

See Also:
password(String,String,Object)

password

public String password(String name,
                       String extra)
Creates a password input field with the specified name and the specified extra arguments with no default value.

See Also:
password(String,String,Object)

password

public String password(String name,
                       String extra,
                       Object defaultValue)
Creates a password input field with the specified name, extra arguments and default value. For example, a call to password("foo", "size=\"5\"", "bar") would result in an input field looking like:
 <input type="password" name="foo" value="bar" size="5">
 
Assuming the foo parameter had no pre-existing value.


submit

public String submit(String text)
Constructs a submit element with the name submit and the specified button text.


submitExtra

public String submitExtra(String text,
                          String extra)
Constructs a submit element with the name submit and the specified button text with the specified extra text.


submit

public String submit(String name,
                     String text)
Constructs a submit element with the specified parameter name and the specified button text.


submitExtra

public String submitExtra(String name,
                          String text,
                          String extra)
Constructs a submit element with the specified parameter name and the specified button text with the specified extra text.


imageSubmit

public String imageSubmit(String name,
                          String imagePath)
Constructs a image submit element with the specified parameter name and image path.


imageSubmit

public String imageSubmit(String name,
                          String value,
                          String imagePath)
Constructs a image submit element with the specified parameter name and image path.


imageSubmit

public String imageSubmit(String name,
                          String value,
                          String imagePath,
                          String altText)
Constructs a image submit element with the specified parameter name and image path.


button

public String button(String name,
                     String text,
                     String extra)
Constructs a button input element with the specified parameter name, the specified button text, and the specified extra text.


hidden

public String hidden(String name)
Constructs a hidden element with the specified parameter name where the value is extracted from the appropriate request parameter.


hidden

public String hidden(String name,
                     Object defaultValue)
Constructs a hidden element with the specified parameter name where the value is extracted from the appropriate request parameter unless there is no value in which case the supplied default value is used.


fixedHidden

public String fixedHidden(String name,
                          Object value)
Constructs a fixed hidden element with the specified parameter name and value. The contents of the parameter of the same name are ignored when creating this element.


action

public String action(String value)
Generates a hidden form field named action with the specified value. This is handy when you have multiple forms submitting to the same servlet and you need to distinguist the action desired by the user.


checkbox

public String checkbox(String name,
                       boolean defaultValue)
Constructs a checkbox input field with the specified name and default value.


fixedCheckbox

public String fixedCheckbox(String name,
                            boolean value)
Constructs a checkbox input field with the specified name and value.


option

public String option(String name,
                     String value,
                     String item,
                     Object defaultValue)
Constructs an option entry for a select menu with the specified name, value, item, and default selected value.


fixedOption

public String fixedOption(String name,
                          String value,
                          String item,
                          Object selectedValue)
Constructs an option entry for a select menu with the specified name, value, item, and selected value.


radio

public String radio(String name,
                    String value)
Creates a radio button with the specified name and value.


radio

public String radio(String name,
                    String value,
                    String defaultValue)
Creates a radio button with the specified name and value.


textarea

public String textarea(String name,
                       String extra,
                       Object defaultValue)
Constructs a text area with the specified name, optional extra parameters, and default text.


fixedTextarea

public String fixedTextarea(String name,
                            String extra,
                            Object value)
Construct a text area with the specified name, optional extra parameters and the specified text.


input

protected String input(String type,
                       String name,
                       String extra,
                       Object defaultValue)
Generates an input form field with the specified type, name, defaultValue and extra attributes.


fixedInput

protected String fixedInput(String type,
                            String name,
                            Object value,
                            String extra)
Generates an input form field with the specified type, name, value and extra attributes. The value is not fetched from the request parameters but is always the value supplied.


getValue

protected String getValue(String name,
                          Object defaultValue)
Fetches the requested value from the servlet request and entifies it appropriately.


getParameter

protected String getParameter(String name)
Returns value of the specified query parameter or null if it is not set.


getCloseBrace

protected String getCloseBrace()
Returns the string used to close unmatched tags.



Copyright © 2000-2008 Michael Bayne. All Rights Reserved.