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

java.lang.Object
  extended by 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:
EditorAwareTag

public class FormTag
extends AbstractHtmlElementTag

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

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

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

Since:
2.0
Author:
Rob Harrop, Juergen Hoeller, Scott Andrews
See Also:
SimpleFormController

Field Summary
private static java.lang.String ACCEPT_CHARSET_ATTRIBUTE
           
private  java.lang.String acceptCharset
           
private  java.lang.String action
           
private static java.lang.String ACTION_ATTRIBUTE
           
private  java.lang.String autocomplete
           
private static java.lang.String AUTOCOMPLETE_ATTRIBUTE
           
static java.lang.String DEFAULT_COMMAND_NAME
          The default attribute name: "command"
private static java.lang.String DEFAULT_METHOD
          The default HTTP method using which form values are sent to the server: "post"
private static java.lang.String DEFAULT_METHOD_PARAM
          Default method parameter, i.e.
private  java.lang.String enctype
           
private static java.lang.String ENCTYPE_ATTRIBUTE
           
private static java.lang.String FORM_TAG
           
private static java.lang.String INPUT_TAG
           
private  java.lang.String method
           
private static java.lang.String METHOD_ATTRIBUTE
           
private  java.lang.String methodParam
           
private static java.lang.String MODEL_ATTRIBUTE
          The name of the 'modelAttribute' setting
static java.lang.String MODEL_ATTRIBUTE_VARIABLE_NAME
          The name of the javax.servlet.jsp.PageContext attribute under which the form object name is exposed.
private  java.lang.String modelAttribute
           
private  java.lang.String name
           
private static java.lang.String NAME_ATTRIBUTE
           
private  java.lang.String onreset
           
private static java.lang.String ONRESET_ATTRIBUTE
           
private  java.lang.String onsubmit
           
private static java.lang.String ONSUBMIT_ATTRIBUTE
           
private  java.lang.String previousNestedPath
          Caching a previous nested path, so that it may be reset
private  TagWriter tagWriter
           
private  java.lang.String target
           
private static java.lang.String TARGET_ATTRIBUTE
           
private static java.lang.String TYPE_ATTRIBUTE
           
private static java.lang.String VALUE_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_VARIABLE_NAME, NESTED_PATH_VARIABLE_NAME
 
Fields inherited from class org.springframework.web.servlet.tags.RequestContextAwareTag
logger, REQUEST_CONTEXT_PAGE_ATTRIBUTE
 
Constructor Summary
FormTag()
           
 
Method Summary
protected  java.lang.String autogenerateId()
          Autogenerated IDs correspond to the form object name.
 int doEndTag()
          Closes the 'form' block tag and removes the form object name from the javax.servlet.jsp.PageContext.
 void doFinally()
          Clears the stored TagWriter.
protected  java.lang.String getAcceptCharset()
          Get the value of the 'acceptCharset' attribute.
protected  java.lang.String getAction()
          Get the value of the 'action' attribute.
protected  java.lang.String getAutocomplete()
          Get the value of the 'autocomplete' attribute.
protected  java.lang.String getCommandName()
          Get the name of the form attribute in the model.
protected  java.lang.String getEnctype()
          Get the value of the 'enctype' attribute.
protected  java.lang.String getMethod()
          Get the value of the 'method' attribute.
protected  java.lang.String getMethodParameter()
          Get the name of the request param for non-browser supported HTTP methods.
protected  java.lang.String getModelAttribute()
          Get the name of the form attribute in the model.
protected  java.lang.String getName()
          Get the value of the 'name' attribute.
protected  java.lang.String getOnreset()
          Get the value of the 'onreset' attribute.
protected  java.lang.String getOnsubmit()
          Get the value of the 'onsubmit' attribute.
 java.lang.String getTarget()
          Get the value of the 'target' attribute.
protected  boolean isMethodBrowserSupported(java.lang.String method)
          Determine if the HTTP method is supported by browsers (i.e.
protected  java.lang.String resolveAction()
          Resolve the value of the 'action' attribute.
protected  java.lang.String resolveCssClass()
          Override resolve CSS class since error class is not supported.
protected  java.lang.String resolveModelAttribute()
          Resolves and returns the name of the form object.
 void setAcceptCharset(java.lang.String acceptCharset)
          Set the value of the 'acceptCharset' attribute.
 void setAction(java.lang.String action)
          Set the value of the 'action' attribute.
 void setAutocomplete(java.lang.String autocomplete)
          Set the value of the 'autocomplete' attribute.
 void setCommandName(java.lang.String commandName)
          Set the name of the form attribute in the model.
 void setCssErrorClass(java.lang.String cssErrorClass)
          Unsupported for forms.
 void setEnctype(java.lang.String enctype)
          Set the value of the 'enctype' attribute.
 void setMethod(java.lang.String method)
          Set the value of the 'method' attribute.
 void setMethodParam(java.lang.String methodParam)
          Set the name of the request param for non-browser supported HTTP methods.
 void setModelAttribute(java.lang.String modelAttribute)
          Set the name of the form attribute in the model.
 void setName(java.lang.String name)
          Set the value of the 'name' attribute.
 void setOnreset(java.lang.String onreset)
          Set the value of the 'onreset' attribute.
 void setOnsubmit(java.lang.String onsubmit)
          Set the value of the 'onsubmit' attribute.
 void setPath(java.lang.String path)
          Unsupported for forms.
 void setTarget(java.lang.String target)
          Set the value of the 'target' attribute.
protected  int writeTagContent(TagWriter tagWriter)
          Writes the opening part of the block 'form' tag and exposes the form object name in the javax.servlet.jsp.PageContext.
 
Methods inherited from class org.springframework.web.servlet.tags.form.AbstractHtmlElementTag
getCssClass, getCssErrorClass, getCssStyle, getDir, getDynamicAttributes, getLang, getOnclick, getOndblclick, getOnkeydown, getOnkeypress, getOnkeyup, getOnmousedown, getOnmousemove, getOnmouseout, getOnmouseover, getOnmouseup, getTabindex, getTitle, setCssClass, setCssStyle, setDir, setDynamicAttribute, setLang, setOnclick, setOndblclick, setOnkeydown, setOnkeypress, setOnkeyup, setOnmousedown, setOnmousemove, setOnmouseout, setOnmouseover, setOnmouseup, setTabindex, setTitle, writeDefaultAttributes, writeOptionalAttributes
 
Methods inherited from class org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag
convertToDisplayString, getBindStatus, getBoundValue, getEditor, getId, getNestedPath, getPath, getPropertyEditor, getPropertyPath, resolveId, setId
 
Methods inherited from class org.springframework.web.servlet.tags.form.AbstractFormTag
createTagWriter, doStartTagInternal, evaluate, evaluateBoolean, getDisplayString, getDisplayString, isDefaultHtmlEscape, 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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_METHOD

private static final java.lang.String DEFAULT_METHOD
The default HTTP method using which form values are sent to the server: "post"

See Also:
Constant Field Values

DEFAULT_COMMAND_NAME

public static final java.lang.String DEFAULT_COMMAND_NAME
The default attribute name: "command"

See Also:
Constant Field Values

MODEL_ATTRIBUTE

private static final java.lang.String MODEL_ATTRIBUTE
The name of the 'modelAttribute' setting

See Also:
Constant Field Values

MODEL_ATTRIBUTE_VARIABLE_NAME

public static final java.lang.String MODEL_ATTRIBUTE_VARIABLE_NAME
The name of the javax.servlet.jsp.PageContext attribute under which the form object name is exposed.


DEFAULT_METHOD_PARAM

private static final java.lang.String DEFAULT_METHOD_PARAM
Default method parameter, i.e. _method.

See Also:
Constant Field Values

FORM_TAG

private static final java.lang.String FORM_TAG
See Also:
Constant Field Values

INPUT_TAG

private static final java.lang.String INPUT_TAG
See Also:
Constant Field Values

ACTION_ATTRIBUTE

private static final java.lang.String ACTION_ATTRIBUTE
See Also:
Constant Field Values

METHOD_ATTRIBUTE

private static final java.lang.String METHOD_ATTRIBUTE
See Also:
Constant Field Values

TARGET_ATTRIBUTE

private static final java.lang.String TARGET_ATTRIBUTE
See Also:
Constant Field Values

ENCTYPE_ATTRIBUTE

private static final java.lang.String ENCTYPE_ATTRIBUTE
See Also:
Constant Field Values

ACCEPT_CHARSET_ATTRIBUTE

private static final java.lang.String ACCEPT_CHARSET_ATTRIBUTE
See Also:
Constant Field Values

ONSUBMIT_ATTRIBUTE

private static final java.lang.String ONSUBMIT_ATTRIBUTE
See Also:
Constant Field Values

ONRESET_ATTRIBUTE

private static final java.lang.String ONRESET_ATTRIBUTE
See Also:
Constant Field Values

AUTOCOMPLETE_ATTRIBUTE

private static final java.lang.String AUTOCOMPLETE_ATTRIBUTE
See Also:
Constant Field Values

NAME_ATTRIBUTE

private static final java.lang.String NAME_ATTRIBUTE
See Also:
Constant Field Values

VALUE_ATTRIBUTE

private static final java.lang.String VALUE_ATTRIBUTE
See Also:
Constant Field Values

TYPE_ATTRIBUTE

private static final java.lang.String TYPE_ATTRIBUTE
See Also:
Constant Field Values

tagWriter

private TagWriter tagWriter

modelAttribute

private java.lang.String modelAttribute

name

private java.lang.String name

action

private java.lang.String action

method

private java.lang.String method

target

private java.lang.String target

enctype

private java.lang.String enctype

acceptCharset

private java.lang.String acceptCharset

onsubmit

private java.lang.String onsubmit

onreset

private java.lang.String onreset

autocomplete

private java.lang.String autocomplete

methodParam

private java.lang.String methodParam

previousNestedPath

private java.lang.String previousNestedPath
Caching a previous nested path, so that it may be reset

Constructor Detail

FormTag

public FormTag()
Method Detail

setModelAttribute

public void setModelAttribute(java.lang.String modelAttribute)
Set the name of the form attribute in the model.

May be a runtime expression.


getModelAttribute

protected java.lang.String getModelAttribute()
Get the name of the form attribute in the model.


setCommandName

public void setCommandName(java.lang.String commandName)
Set the name of the form attribute in the model.

May be a runtime expression.

See Also:
setModelAttribute(java.lang.String)

getCommandName

protected java.lang.String getCommandName()
Get the name of the form attribute in the model.

See Also:
getModelAttribute()

setName

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

May be a runtime expression.

Name is not a valid attribute for form on XHTML 1.0. However, it is sometimes needed for backward compatibility.


getName

protected java.lang.String getName()
                            throws JspException
Get the value of the 'name' attribute.

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

setAction

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

May be a runtime expression.


getAction

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


setMethod

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

May be a runtime expression.


getMethod

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


setTarget

public void setTarget(java.lang.String target)
Set the value of the 'target' attribute.

May be a runtime expression.


getTarget

public java.lang.String getTarget()
Get the value of the 'target' attribute.


setEnctype

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

May be a runtime expression.


getEnctype

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


setAcceptCharset

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

May be a runtime expression.


getAcceptCharset

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


setOnsubmit

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

May be a runtime expression.


getOnsubmit

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


setOnreset

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

May be a runtime expression.


getOnreset

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


setAutocomplete

public void setAutocomplete(java.lang.String autocomplete)
Set the value of the 'autocomplete' attribute. May be a runtime expression.


getAutocomplete

protected java.lang.String getAutocomplete()
Get the value of the 'autocomplete' attribute.


setMethodParam

public void setMethodParam(java.lang.String methodParam)
Set the name of the request param for non-browser supported HTTP methods.


getMethodParameter

protected java.lang.String getMethodParameter()
Get the name of the request param for non-browser supported HTTP methods.


isMethodBrowserSupported

protected boolean isMethodBrowserSupported(java.lang.String method)
Determine if the HTTP method is supported by browsers (i.e. GET or POST).


writeTagContent

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

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

autogenerateId

protected java.lang.String autogenerateId()
                                   throws JspException
Autogenerated IDs correspond to the form object name.

Overrides:
autogenerateId in class AbstractDataBoundFormElementTag
Throws:
JspException

resolveModelAttribute

protected java.lang.String resolveModelAttribute()
                                          throws JspException
Resolves and returns the name of the form object.

Throws:
java.lang.IllegalArgumentException - if the form object resolves to null
JspException

resolveAction

protected java.lang.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 form object name from the javax.servlet.jsp.PageContext.

Throws:
JspException

doFinally

public void doFinally()
Clears the stored TagWriter.

Overrides:
doFinally in class AbstractDataBoundFormElementTag

resolveCssClass

protected java.lang.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(java.lang.String path)
Unsupported for forms.

Overrides:
setPath in class AbstractDataBoundFormElementTag
Throws:
java.lang.UnsupportedOperationException - always

setCssErrorClass

public void setCssErrorClass(java.lang.String cssErrorClass)
Unsupported for forms.

Overrides:
setCssErrorClass in class AbstractHtmlElementTag
Throws:
java.lang.UnsupportedOperationException - always