The Spring Framework

org.springframework.web.servlet.tags.form
Class FormTag

java.lang.Object
  extended by javax.servlet.jsp.tagext.TagSupport
      extended by org.springframework.web.servlet.tags.RequestContextAwareTag
          extended by org.springframework.web.servlet.tags.HtmlEscapingAwareTag
              extended by org.springframework.web.servlet.tags.form.AbstractFormTag
                  extended by org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag
                      extended by org.springframework.web.servlet.tags.form.AbstractHtmlElementTag
                          extended by org.springframework.web.servlet.tags.form.FormTag
All Implemented Interfaces:
Serializable, IterationTag, JspTag, Tag, TryCatchFinally

public class FormTag
extends AbstractHtmlElementTag

Databinding-aware JSP tag for rendering an HTML 'form' whose inner elements are bound to properties on a command object.

Users should place the command object into the ModelAndView when populating the data for their view. The name of this command object can be configured using the commandName property.

The default value for the commandName property is 'command' which corresponds to the default name when using the SimpleFormController.

Inner tags can access the name of the command object via the PageContext. The attribute name is defined in AbstractDataBoundFormElementTag.COMMAND_NAME_VARIABLE_NAME.

Since:
2.0
Author:
Rob Harrop, Juergen Hoeller
See Also:
SimpleFormController, Serialized Form

Field Summary
static String ACCEPT_CHARSET_ATTRIBUTE
           
static String ACTION_ATTRIBUTE
           
static String DEFAULT_COMMAND_NAME
          The default command object name: "command"
static String ENCTYPE_ATTRIBUTE
           
static String METHOD_ATTRIBUTE
           
static String NAME_ATTRIBUTE
           
static String ONRESET_ATTRIBUTE
           
static String ONSUBMIT_ATTRIBUTE
           
 
Fields inherited from class org.springframework.web.servlet.tags.form.AbstractHtmlElementTag
CLASS_ATTRIBUTE, DIR_ATTRIBUTE, LANG_ATTRIBUTE, ONCLICK_ATTRIBUTE, ONDBLCLICK_ATTRIBUTE, ONKEYDOWN_ATTRIBUTE, ONKEYPRESS_ATTRIBUTE, ONKEYUP_ATTRIBUTE, ONMOUSEDOWN_ATTRIBUTE, ONMOUSEMOVE_ATTRIBUTE, ONMOUSEOUT_ATTRIBUTE, ONMOUSEOVER_ATTRIBUTE, ONMOUSEUP_ATTRIBUTE, STYLE_ATTRIBUTE, TABINDEX_ATTRIBUTE, TITLE_ATTRIBUTE
 
Fields inherited from class org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag
COMMAND_NAME_ATTRIBUTE, COMMAND_NAME_VARIABLE_NAME, ID_ATTRIBUTE
 
Fields inherited from class org.springframework.web.servlet.tags.RequestContextAwareTag
logger, REQUEST_CONTEXT_PAGE_ATTRIBUTE
 
Fields inherited from class javax.servlet.jsp.tagext.TagSupport
pageContext
 
Fields inherited from interface javax.servlet.jsp.tagext.IterationTag
EVAL_BODY_AGAIN
 
Fields inherited from interface javax.servlet.jsp.tagext.Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE
 
Constructor Summary
FormTag()
           
 
Method Summary
protected  String autogenerateId()
          Autogenerated IDs correspond to the command name.
 int doEndTag()
          Closes the 'form' block tag and removes the command name from the PageContext.
 void doFinally()
          Clears the stored TagWriter.
protected  String getAcceptCharset()
          Get the value of the 'acceptCharset' attribute.
protected  String getAction()
          Get the value of the 'action' attribute.
protected  String getCommandName()
          Get the value of the 'commandName' attribute.
protected  String getEnctype()
          Get the value of the 'enctype' attribute.
protected  String getMethod()
          Get the value of the 'method' attribute.
protected  String getName()
          Name is not a valid attribute for form on XHTML 1.0.
protected  String getOnreset()
          Get the value of the 'onreset' attribute.
protected  String getOnsubmit()
          Get the value of the 'onsubmit' attribute.
protected  String resolveAction()
          Resolve the value of the 'action' attribute.
protected  String resolveCommandName()
          Resolves and returns the name of the command object.
protected  String resolveCssClass()
          Override resolve CSS class since error class is not supported.
 void setAcceptCharset(String acceptCharset)
          Set the value of the 'acceptCharset' attribute.
 void setAction(String action)
          Set the value of the 'action' attribute.
 void setCommandName(String commandName)
          Set the name of the command object.
 void setCssErrorClass(String cssErrorClass)
          Unsupported for forms.
 void setEnctype(String enctype)
          Set the value of the 'enctype' attribute.
 void setMethod(String method)
          Set the value of the 'method' attribute.
 void setName(String name)
          Set the value of the 'name' attribute.
 void setOnreset(String onreset)
          Set the value of the 'onreset' attribute.
 void setOnsubmit(String onsubmit)
          Set the value of the 'onsubmit' attribute.
 void setPath(String path)
          Unsupported for forms.
protected  int writeTagContent(TagWriter tagWriter)
          Writes the opening part of the block 'form' tag and exposes the command name in the PageContext.
 
Methods inherited from class org.springframework.web.servlet.tags.form.AbstractHtmlElementTag
getCssClass, getCssErrorClass, getCssStyle, getDir, getLang, getOnclick, getOndblclick, getOnkeydown, getOnkeypress, getOnkeyup, getOnmousedown, getOnmousemove, getOnmouseout, getOnmouseover, getOnmouseup, getTabindex, getTitle, setCssClass, setCssStyle, setDir, setLang, setOnclick, setOndblclick, setOnkeydown, setOnkeypress, setOnkeyup, setOnmousedown, setOnmousemove, setOnmouseout, setOnmouseover, setOnmouseup, setTabindex, setTitle, writeDefaultAttributes
 
Methods inherited from class org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag
getBindStatus, getBoundValue, getCompletePath, getId, getNestedPath, getPath, getPropertyEditor, setId
 
Methods inherited from class org.springframework.web.servlet.tags.form.AbstractFormTag
createTagWriter, doStartTagInternal, evaluate, getDisplayString, getDisplayString, writeOptionalAttribute
 
Methods inherited from class org.springframework.web.servlet.tags.HtmlEscapingAwareTag
isHtmlEscape, setHtmlEscape
 
Methods inherited from class org.springframework.web.servlet.tags.RequestContextAwareTag
doCatch, doStartTag, getRequestContext
 
Methods inherited from class javax.servlet.jsp.tagext.TagSupport
doAfterBody, findAncestorWithClass, getParent, getValue, getValues, release, removeValue, setPageContext, setParent, setValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_COMMAND_NAME

public static final String DEFAULT_COMMAND_NAME
The default command object name: "command"

See Also:
Constant Field Values

NAME_ATTRIBUTE

public static final String NAME_ATTRIBUTE
See Also:
Constant Field Values

ONSUBMIT_ATTRIBUTE

public static final String ONSUBMIT_ATTRIBUTE
See Also:
Constant Field Values

ONRESET_ATTRIBUTE

public static final String ONRESET_ATTRIBUTE
See Also:
Constant Field Values

METHOD_ATTRIBUTE

public static final String METHOD_ATTRIBUTE
See Also:
Constant Field Values

ACTION_ATTRIBUTE

public static final String ACTION_ATTRIBUTE
See Also:
Constant Field Values

ENCTYPE_ATTRIBUTE

public static final String ENCTYPE_ATTRIBUTE
See Also:
Constant Field Values

ACCEPT_CHARSET_ATTRIBUTE

public static final String ACCEPT_CHARSET_ATTRIBUTE
See Also:
Constant Field Values
Constructor Detail

FormTag

public FormTag()
Method Detail

setCommandName

public void setCommandName(String commandName)
Set the name of the command object.

May be a runtime expression.


getCommandName

protected String getCommandName()
Get the value of the 'commandName' attribute.

May be a runtime expression.


setName

public void setName(String name)
Set the value of the 'name' attribute.

May be a runtime expression.


setAction

public void setAction(String action)
Set the value of the 'action' attribute.

May be a runtime expression.


getAction

protected String getAction()
Get the value of the 'action' attribute.

May be a runtime expression.


setMethod

public void setMethod(String method)
Set the value of the 'method' attribute.

May be a runtime expression.


getMethod

protected String getMethod()
Get the value of the 'method' attribute.

May be a runtime expression.


setEnctype

public void setEnctype(String enctype)
Set the value of the 'enctype' attribute.

May be a runtime expression.


getEnctype

protected String getEnctype()
Get the value of the 'enctype' attribute.

May be a runtime expression.


setAcceptCharset

public void setAcceptCharset(String acceptCharset)
Set the value of the 'acceptCharset' attribute.

May be a runtime expression.


getAcceptCharset

protected String getAcceptCharset()
Get the value of the 'acceptCharset' attribute.

May be a runtime expression.


setOnsubmit

public void setOnsubmit(String onsubmit)
Set the value of the 'onsubmit' attribute.

May be a runtime expression.


getOnsubmit

protected String getOnsubmit()
Get the value of the 'onsubmit' attribute.

May be a runtime expression.


setOnreset

public void setOnreset(String onreset)
Set the value of the 'onreset' attribute.

May be a runtime expression.


getOnreset

protected String getOnreset()
Get the value of the 'onreset' attribute.

May be a runtime expression.


writeTagContent

protected int writeTagContent(TagWriter tagWriter)
                       throws JspException
Writes the opening part of the block 'form' tag and exposes the command name in the PageContext.

Specified by:
writeTagContent in class AbstractFormTag
Parameters:
tagWriter - the TagWriter to which the form content is to be written
Returns:
Tag.EVAL_BODY_INCLUDE
Throws:
JspException

getName

protected String getName()
                  throws JspException
Name is not a valid attribute for form on XHTML 1.0. However, it is sometimes needed for backward compatibility.

Overrides:
getName in class AbstractDataBoundFormElementTag
Returns:
the value for the HTML 'name' attribute
Throws:
JspException

autogenerateId

protected String autogenerateId()
                         throws JspException
Autogenerated IDs correspond to the command name.

Overrides:
autogenerateId in class AbstractDataBoundFormElementTag
Throws:
JspException

resolveCommandName

protected String resolveCommandName()
                             throws JspException
Resolves and returns the name of the command object.

Throws:
IllegalArgumentException - if the command object resolves to null
JspException

resolveAction

protected String resolveAction()
                        throws JspException
Resolve the value of the 'action' attribute.

If the user configured an 'action' value then the result of evaluating this value is used. Otherwise, the originating URI is used.

Returns:
the value that is to be used for the 'action' attribute
Throws:
JspException

doEndTag

public int doEndTag()
             throws JspException
Closes the 'form' block tag and removes the command name from the PageContext.

Specified by:
doEndTag in interface Tag
Overrides:
doEndTag in class TagSupport
Throws:
JspException

doFinally

public void doFinally()
Clears the stored TagWriter.

Specified by:
doFinally in interface TryCatchFinally
Overrides:
doFinally in class AbstractDataBoundFormElementTag

resolveCssClass

protected String resolveCssClass()
                          throws JspException
Override resolve CSS class since error class is not supported.

Overrides:
resolveCssClass in class AbstractHtmlElementTag
Throws:
JspException

setPath

public void setPath(String path)
Unsupported for forms.

Overrides:
setPath in class AbstractDataBoundFormElementTag
Throws:
UnsupportedOperationException - always

setCssErrorClass

public void setCssErrorClass(String cssErrorClass)
Unsupported for forms.

Overrides:
setCssErrorClass in class AbstractHtmlElementTag
Throws:
UnsupportedOperationException - always

The Spring Framework

Copyright © 2002-2007 The Spring Framework.