Class FormTag
- All Implemented Interfaces:
DynamicAttributes,IterationTag,JspTag,Tag,TryCatchFinally,Serializable,EditorAwareTag
<form> tag renders an HTML 'form' tag and exposes a binding path to
inner tags for binding.
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.
| Attribute | Required? | Runtime Expression? | Description |
|---|---|---|---|
acceptCharset |
false |
true |
Specifies the list of character encodings for input data that is accepted by the server processing this form. The value is a space- and/or comma-delimited list of charset values. The client must interpret this list as an exclusive-or list, i.e., the server is able to accept any single character encoding per entity received. |
action |
false |
true |
HTML Required Attribute |
cssClass |
false |
true |
HTML Optional Attribute |
cssStyle |
false |
true |
HTML Optional Attribute |
dir |
false |
true |
HTML Standard Attribute |
enctype |
false |
true |
HTML Optional Attribute |
htmlEscape |
false |
true |
Enable/disable HTML escaping of rendered values. |
id |
false |
true |
HTML Standard Attribute |
lang |
false |
true |
HTML Standard Attribute |
method |
false |
true |
HTML Optional Attribute |
methodParam |
false |
true |
The parameter name used for HTTP methods other then GET and POST. Default is '_method'. |
modelAttribute |
false |
true |
Name of the model attribute under which the form object is exposed. Defaults to 'command'. |
name |
false |
true |
HTML Standard Attribute - added for backwards compatibility cases |
onclick |
false |
true |
HTML Event Attribute |
ondblclick |
false |
true |
HTML Event Attribute |
onkeydown |
false |
true |
HTML Event Attribute |
onkeypress |
false |
true |
HTML Event Attribute |
onkeyup |
false |
true |
HTML Event Attribute |
onmousedown |
false |
true |
HTML Event Attribute |
onmousemove |
false |
true |
HTML Event Attribute |
onmouseout |
false |
true |
HTML Event Attribute |
onmouseover |
false |
true |
HTML Event Attribute |
onmouseup |
false |
true |
HTML Event Attribute |
onreset |
false |
true |
HTML Event Attribute |
onsubmit |
false |
true |
HTML Event Attribute |
servletRelativeAction |
false |
true |
Action reference to be appended to the current servlet path |
target |
false |
true |
HTML Optional Attribute |
title |
false |
true |
HTML Standard Attribute |
- Since:
- 2.0
- Author:
- Rob Harrop, Juergen Hoeller, Scott Andrews, Rossen Stoyanchev
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe default attribute name: "command".static final StringThe name of thePageContextattribute under which the form object name is exposed.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_ATTRIBUTEFields inherited from class org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag
NESTED_PATH_VARIABLE_NAMEFields inherited from class org.springframework.web.servlet.tags.RequestContextAwareTag
logger, REQUEST_CONTEXT_PAGE_ATTRIBUTEFields inherited from class jakarta.servlet.jsp.tagext.TagSupport
pageContextFields inherited from interface jakarta.servlet.jsp.tagext.IterationTag
EVAL_BODY_AGAINFields inherited from interface jakarta.servlet.jsp.tagext.Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringAutogenerated IDs correspond to the form object name.intdoEndTag()Closes the 'form' block tag and removes the form object name from thePageContext.voidClears the storedTagWriter.protected StringGet the value of the 'acceptCharset' attribute.protected StringGet the value of the 'action' attribute.protected StringGet the value of the 'autocomplete' attribute.protected StringGet the value of the 'enctype' attribute.protected StringGet the value of the 'method' attribute.protected StringGet the name of the request param for non-browser supported HTTP methods.protected StringGet the name of the form attribute in the model.protected StringgetName()Get the value of the 'name' attribute.protected StringGet the value of the 'onreset' attribute.protected StringGet the value of the 'onsubmit' attribute.protected StringGet the servlet-relative value of the 'action' attribute.Get the value of the 'target' attribute.protected booleanisMethodBrowserSupported(String method) Determine if the HTTP method is supported by browsers (i.e.protected StringResolve the value of the 'action' attribute.protected StringOverride resolve CSS class since error class is not supported.protected StringResolvesand returns the name of the form object.voidsetAcceptCharset(String acceptCharset) Set the value of the 'acceptCharset' attribute.voidSet the value of the 'action' attribute.voidsetAutocomplete(String autocomplete) Set the value of the 'autocomplete' attribute.voidsetCssErrorClass(String cssErrorClass) Unsupported for forms.voidsetEnctype(String enctype) Set the value of the 'enctype' attribute.voidSet the value of the 'method' attribute.voidsetMethodParam(String methodParam) Set the name of the request param for non-browser supported HTTP methods.voidsetModelAttribute(String modelAttribute) Set the name of the form attribute in the model.voidSet the value of the 'name' attribute.voidsetOnreset(String onreset) Set the value of the 'onreset' attribute.voidsetOnsubmit(String onsubmit) Set the value of the 'onsubmit' attribute.voidUnsupported for forms.voidsetServletRelativeAction(String servletRelativeAction) Set the value of the 'action' attribute through a value that is to be appended to the current servlet path.voidSet the value of the 'target' attribute.protected intwriteTagContent(TagWriter tagWriter) Writes the opening part of the block 'form' tag and exposes the form object name in thePageContext.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, isValidDynamicAttribute, setCssClass, setCssStyle, setDir, setDynamicAttribute, setLang, setOnclick, setOndblclick, setOnkeydown, setOnkeypress, setOnkeyup, setOnmousedown, setOnmousemove, setOnmouseout, setOnmouseover, setOnmouseup, setTabindex, setTitle, writeDefaultAttributes, writeOptionalAttributesMethods inherited from class org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag
convertToDisplayString, getBindStatus, getBoundValue, getEditor, getId, getNestedPath, getPath, getPropertyEditor, getPropertyPath, processFieldValue, resolveId, setIdMethods inherited from class org.springframework.web.servlet.tags.form.AbstractFormTag
createTagWriter, doStartTagInternal, evaluate, getDisplayString, getDisplayString, isDefaultHtmlEscape, writeOptionalAttributeMethods inherited from class org.springframework.web.servlet.tags.HtmlEscapingAwareTag
htmlEscape, isHtmlEscape, isResponseEncodedHtmlEscape, setHtmlEscapeMethods inherited from class org.springframework.web.servlet.tags.RequestContextAwareTag
doCatch, doStartTag, getRequestContextMethods inherited from class jakarta.servlet.jsp.tagext.TagSupport
doAfterBody, findAncestorWithClass, getParent, getValue, getValues, release, removeValue, setPageContext, setParent, setValue
-
Field Details
-
DEFAULT_COMMAND_NAME
The default attribute name: "command".- See Also:
-
MODEL_ATTRIBUTE_VARIABLE_NAME
The name of thePageContextattribute under which the form object name is exposed.
-
-
Constructor Details
-
FormTag
public FormTag()
-
-
Method Details
-
setModelAttribute
Set the name of the form attribute in the model.May be a runtime expression.
-
getModelAttribute
Get the name of the form attribute in the model. -
setName
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
Get the value of the 'name' attribute.- Overrides:
getNamein classAbstractDataBoundFormElementTag- Returns:
- the value for the HTML '
name' attribute - Throws:
JspException
-
setAction
Set the value of the 'action' attribute.May be a runtime expression.
-
getAction
Get the value of the 'action' attribute. -
setServletRelativeAction
Set the value of the 'action' attribute through a value that is to be appended to the current servlet path.May be a runtime expression.
- Since:
- 3.2.3
-
getServletRelativeAction
Get the servlet-relative value of the 'action' attribute.- Since:
- 3.2.3
-
setMethod
Set the value of the 'method' attribute.May be a runtime expression.
-
getMethod
Get the value of the 'method' attribute. -
setTarget
Set the value of the 'target' attribute.May be a runtime expression.
-
getTarget
Get the value of the 'target' attribute. -
setEnctype
Set the value of the 'enctype' attribute.May be a runtime expression.
-
getEnctype
Get the value of the 'enctype' attribute. -
setAcceptCharset
Set the value of the 'acceptCharset' attribute.May be a runtime expression.
-
getAcceptCharset
Get the value of the 'acceptCharset' attribute. -
setOnsubmit
Set the value of the 'onsubmit' attribute.May be a runtime expression.
-
getOnsubmit
Get the value of the 'onsubmit' attribute. -
setOnreset
Set the value of the 'onreset' attribute.May be a runtime expression.
-
getOnreset
Get the value of the 'onreset' attribute. -
setAutocomplete
Set the value of the 'autocomplete' attribute. May be a runtime expression. -
getAutocomplete
Get the value of the 'autocomplete' attribute. -
setMethodParam
Set the name of the request param for non-browser supported HTTP methods. -
getMethodParam
Get the name of the request param for non-browser supported HTTP methods.- Since:
- 4.2.3
-
isMethodBrowserSupported
Determine if the HTTP method is supported by browsers (i.e. GET or POST). -
writeTagContent
Writes the opening part of the block 'form' tag and exposes the form object name in thePageContext.- Specified by:
writeTagContentin classAbstractFormTag- Parameters:
tagWriter- theTagWriterto which the form content is to be written- Returns:
Tag.EVAL_BODY_INCLUDE- Throws:
JspException
-
autogenerateId
Autogenerated IDs correspond to the form object name.- Overrides:
autogenerateIdin classAbstractDataBoundFormElementTag- Throws:
JspException
-
resolveModelAttribute
Resolvesand returns the name of the form object.- Throws:
IllegalArgumentException- if the form object resolves tonullJspException
-
resolveAction
Resolve the value of the 'action' attribute.If the user configured an '
action' value then the result of evaluating this value is used. If the user configured an 'servletRelativeAction' value then the value is prepended with the context and servlet paths, and the result is used. Otherwise, theoriginating URIis used.- Returns:
- the value that is to be used for the '
action' attribute - Throws:
JspException
-
doEndTag
Closes the 'form' block tag and removes the form object name from thePageContext.- Specified by:
doEndTagin interfaceTag- Overrides:
doEndTagin classTagSupport- Throws:
JspException
-
doFinally
public void doFinally()Clears the storedTagWriter.- Specified by:
doFinallyin interfaceTryCatchFinally- Overrides:
doFinallyin classAbstractDataBoundFormElementTag
-
resolveCssClass
Override resolve CSS class since error class is not supported.- Overrides:
resolveCssClassin classAbstractHtmlElementTag- Throws:
JspException
-
setPath
Unsupported for forms.- Overrides:
setPathin classAbstractDataBoundFormElementTag- Throws:
UnsupportedOperationException- always
-
setCssErrorClass
Unsupported for forms.- Overrides:
setCssErrorClassin classAbstractHtmlElementTag- Throws:
UnsupportedOperationException- always
-