Class FormTag
- java.lang.Object
- javax.servlet.jsp.tagext.TagSupport
- org.springframework.web.servlet.tags.RequestContextAwareTag
- org.springframework.web.servlet.tags.HtmlEscapingAwareTag
- org.springframework.web.servlet.tags.form.AbstractFormTag
- org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag
- org.springframework.web.servlet.tags.form.AbstractHtmlElementTag
- org.springframework.web.servlet.tags.form.FormTag
- All Implemented Interfaces:
Serializable
,DynamicAttributes
,IterationTag
,JspTag
,Tag
,TryCatchFinally
,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.- Since:
- 2.0
- Author:
- Rob Harrop, Juergen Hoeller, Scott Andrews, Rossen Stoyanchev
- See Also:
- Serialized Form
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_COMMAND_NAME
The default attribute name: "command"static String
MODEL_ATTRIBUTE_VARIABLE_NAME
The name of thePageContext
attribute 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_ATTRIBUTE
Fields inherited from class org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag
NESTED_PATH_VARIABLE_NAME
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
Constructors Constructor Description FormTag()
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected String
autogenerateId()
Autogenerated IDs correspond to the form object name.int
doEndTag()
Closes the 'form
' block tag and removes the form object name from thePageContext
.void
doFinally()
Clears the storedTagWriter
.protected String
getAcceptCharset()
Get the value of the 'acceptCharset
' attribute.protected String
getAction()
Get the value of the 'action
' attribute.protected String
getAutocomplete()
Get the value of the 'autocomplete
' attribute.protected String
getCommandName()
Deprecated.as of Spring 4.3, in favor ofgetModelAttribute()
protected String
getEnctype()
Get the value of the 'enctype
' attribute.protected String
getMethod()
Get the value of the 'method
' attribute.protected String
getMethodParam()
Get the name of the request param for non-browser supported HTTP methods.protected String
getMethodParameter()
Deprecated.as of 4.2.3, in favor ofgetMethodParam()
which is a proper pairing forsetMethodParam(String)
protected String
getModelAttribute()
Get the name of the form attribute in the model.protected String
getName()
Get the value of the 'name
' attribute.protected String
getOnreset()
Get the value of the 'onreset
' attribute.protected String
getOnsubmit()
Get the value of the 'onsubmit
' attribute.protected String
getServletRelativeAction()
Get the servlet-relative value of the 'action
' attribute.String
getTarget()
Get the value of the 'target
' attribute.protected boolean
isMethodBrowserSupported(String method)
Determine if the HTTP method is supported by browsers (i.e.protected String
resolveAction()
Resolve the value of the 'action
' attribute.protected String
resolveCssClass()
Override resolve CSS class since error class is not supported.protected String
resolveModelAttribute()
Resolves
and returns the name of the form object.void
setAcceptCharset(String acceptCharset)
Set the value of the 'acceptCharset
' attribute.void
setAction(String action)
Set the value of the 'action
' attribute.void
setAutocomplete(String autocomplete)
Set the value of the 'autocomplete
' attribute.void
setCommandName(String commandName)
Deprecated.as of Spring 4.3, in favor ofsetModelAttribute(java.lang.String)
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
setMethodParam(String methodParam)
Set the name of the request param for non-browser supported HTTP methods.void
setModelAttribute(String modelAttribute)
Set the name of the form attribute in the model.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.void
setServletRelativeAction(String servletRelativeAction)
Set the value of the 'action
' attribute through a value that is to be appended to the current servlet path.void
setTarget(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 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, writeOptionalAttributes
Methods inherited from class org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag
convertToDisplayString, getBindStatus, getBoundValue, getEditor, getId, getNestedPath, getPath, getPropertyEditor, getPropertyPath, processFieldValue, resolveId, setId
Methods inherited from class org.springframework.web.servlet.tags.form.AbstractFormTag
createTagWriter, doStartTagInternal, evaluate, getDisplayString, getDisplayString, isDefaultHtmlEscape, writeOptionalAttribute
Methods inherited from class org.springframework.web.servlet.tags.HtmlEscapingAwareTag
htmlEscape, isHtmlEscape, isResponseEncodedHtmlEscape, 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
Field Detail
DEFAULT_COMMAND_NAME
public static final String DEFAULT_COMMAND_NAME
The default attribute name: "command"- See Also:
- Constant Field Values
MODEL_ATTRIBUTE_VARIABLE_NAME
public static final String MODEL_ATTRIBUTE_VARIABLE_NAME
The name of thePageContext
attribute under which the form object name is exposed.
Constructor Detail
FormTag
public FormTag()
Method Detail
setModelAttribute
public void setModelAttribute(String modelAttribute)
Set the name of the form attribute in the model.May be a runtime expression.
getModelAttribute
protected String getModelAttribute()
Get the name of the form attribute in the model.
setCommandName
@Deprecated public void setCommandName(String commandName)
Deprecated.as of Spring 4.3, in favor ofsetModelAttribute(java.lang.String)
Set the name of the form attribute in the model.May be a runtime expression.
- See Also:
setModelAttribute(java.lang.String)
getCommandName
@Deprecated protected String getCommandName()
Deprecated.as of Spring 4.3, in favor ofgetModelAttribute()
Get the name of the form attribute in the model.- See Also:
getModelAttribute()
setName
public void setName(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 String getName() throws JspException
Get the value of the 'name
' attribute.- Overrides:
getName
in classAbstractDataBoundFormElementTag
- Returns:
- the value for the HTML '
name
' attribute - Throws:
JspException
setAction
public void setAction(String action)
Set the value of the 'action
' attribute.May be a runtime expression.
setServletRelativeAction
public void setServletRelativeAction(String servletRelativeAction)
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
protected String getServletRelativeAction()
Get the servlet-relative value of the 'action
' attribute.- Since:
- 3.2.3
setMethod
public void setMethod(String method)
Set the value of the 'method
' attribute.May be a runtime expression.
setTarget
public void setTarget(String target)
Set the value of the 'target
' 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.
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.
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.
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.
setAutocomplete
public void setAutocomplete(String autocomplete)
Set the value of the 'autocomplete
' attribute. May be a runtime expression.
getAutocomplete
protected String getAutocomplete()
Get the value of the 'autocomplete
' attribute.
setMethodParam
public void setMethodParam(String methodParam)
Set the name of the request param for non-browser supported HTTP methods.
getMethodParam
protected String getMethodParam()
Get the name of the request param for non-browser supported HTTP methods.- Since:
- 4.2.3
getMethodParameter
@Deprecated protected String getMethodParameter()
Deprecated.as of 4.2.3, in favor ofgetMethodParam()
which is a proper pairing forsetMethodParam(String)
Get the name of the request param for non-browser supported HTTP methods.
isMethodBrowserSupported
protected boolean isMethodBrowserSupported(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 thePageContext
.- Specified by:
writeTagContent
in classAbstractFormTag
- Parameters:
tagWriter
- theTagWriter
to which the form content is to be written- Returns:
Tag.EVAL_BODY_INCLUDE
- Throws:
JspException
autogenerateId
protected String autogenerateId() throws JspException
Autogenerated IDs correspond to the form object name.- Overrides:
autogenerateId
in classAbstractDataBoundFormElementTag
- Throws:
JspException
resolveModelAttribute
protected String resolveModelAttribute() throws JspException
Resolves
and returns the name of the form object.- Throws:
IllegalArgumentException
- if the form object resolves tonull
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. 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 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 thePageContext
.- Specified by:
doEndTag
in interfaceTag
- Overrides:
doEndTag
in classTagSupport
- Throws:
JspException
doFinally
public void doFinally()
Clears the storedTagWriter
.- Specified by:
doFinally
in interfaceTryCatchFinally
- Overrides:
doFinally
in classAbstractDataBoundFormElementTag
resolveCssClass
protected String resolveCssClass() throws JspException
Override resolve CSS class since error class is not supported.- Overrides:
resolveCssClass
in classAbstractHtmlElementTag
- Throws:
JspException
setPath
public void setPath(String path)
Unsupported for forms.- Overrides:
setPath
in classAbstractDataBoundFormElementTag
- Throws:
UnsupportedOperationException
- always
setCssErrorClass
public void setCssErrorClass(String cssErrorClass)
Unsupported for forms.- Overrides:
setCssErrorClass
in classAbstractHtmlElementTag
- Throws:
UnsupportedOperationException
- always