org.springframework.web.servlet.tags.form

Class FormTag

  • All Implemented Interfaces:
    java.io.Serializable, DynamicAttributes, IterationTag, JspTag, Tag, TryCatchFinally, EditorAwareTag


    public class FormTag
    extends AbstractHtmlElementTag
    The <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 Summary
    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:
    Serialized Form
    • Field Detail

      • DEFAULT_COMMAND_NAME

        public static final java.lang.String DEFAULT_COMMAND_NAME
        The default attribute name: "command".
        See Also:
        Constant Field Values
      • MODEL_ATTRIBUTE_VARIABLE_NAME

        public static final java.lang.String MODEL_ATTRIBUTE_VARIABLE_NAME
        The name of the PageContext attribute under which the form object name is exposed.
    • 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.
      • 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.

      • setAction

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

        May be a runtime expression.

      • getAction

        @Nullable
        protected java.lang.String getAction()
        Get the value of the 'action' attribute.
      • setServletRelativeAction

        public void setServletRelativeAction(@Nullable
                                             java.lang.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

        @Nullable
        protected java.lang.String getServletRelativeAction()
        Get the servlet-relative value of the 'action' attribute.
        Since:
        3.2.3
      • 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

        @Nullable
        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

        @Nullable
        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

        @Nullable
        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

        @Nullable
        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

        @Nullable
        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

        @Nullable
        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.
      • getMethodParam

        protected java.lang.String getMethodParam()
        Get the name of the request param for non-browser supported HTTP methods.
        Since:
        4.2.3
      • isMethodBrowserSupported

        protected boolean isMethodBrowserSupported(java.lang.String method)
        Determine if the HTTP method is supported by browsers (i.e. GET or POST).
      • 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. If the user configured an 'servletRelativeAction' value then the value is prepended with the context and servlet paths, and the result is used. Otherwise, the originating URI is used.

        Returns:
        the value that is to be used for the 'action' attribute
        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