Class LabelTag

All Implemented Interfaces:
jakarta.servlet.jsp.tagext.DynamicAttributes, jakarta.servlet.jsp.tagext.IterationTag, jakarta.servlet.jsp.tagext.JspTag, jakarta.servlet.jsp.tagext.Tag, jakarta.servlet.jsp.tagext.TryCatchFinally, Serializable, EditorAwareTag

public class LabelTag extends AbstractHtmlElementTag
The <label> tag renders a form field label in an HTML 'label' tag.

See the "formTags" showcase application that ships with the full Spring distribution for an example of this class in action.

Attribute Summary

Attribute Required? Runtime Expression? Description

cssClass

false

true

HTML Optional Attribute.

cssErrorClass

false

true

HTML Optional Attribute. Used only when errors are present.

cssStyle

false

true

HTML Optional Attribute

dir

false

true

HTML Standard Attribute

for

false

true

HTML Standard Attribute

htmlEscape

false

true

Enable/disable HTML escaping of rendered values.

id

false

true

HTML Standard Attribute

lang

false

true

HTML Standard Attribute

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

path

true

true

Path to errors object for data binding

tabindex

false

true

HTML Standard Attribute

title

false

true

HTML Standard Attribute

Since:
2.0
Author:
Rob Harrop, Juergen Hoeller
See Also:
  • Constructor Details

    • LabelTag

      public LabelTag()
  • Method Details

    • setFor

      public void setFor(String forId)
      Set the value of the 'for' attribute.

      Defaults to the value of AbstractDataBoundFormElementTag.getPath(); may be a runtime expression.

    • getFor

      protected @Nullable String getFor()
      Get the value of the 'id' attribute.

      May be a runtime expression.

    • writeTagContent

      protected int writeTagContent(TagWriter tagWriter) throws jakarta.servlet.jsp.JspException
      Writes the opening 'label' tag and forces a block tag so that body content is written correctly.
      Specified by:
      writeTagContent in class AbstractFormTag
      Returns:
      Tag.EVAL_BODY_INCLUDE
      Throws:
      jakarta.servlet.jsp.JspException
    • getName

      protected @Nullable String getName() throws jakarta.servlet.jsp.JspException
      Overrides #getName() to always return null, because the 'name' attribute is not supported by the 'label' tag.
      Overrides:
      getName in class AbstractDataBoundFormElementTag
      Returns:
      the value for the HTML 'name' attribute
      Throws:
      jakarta.servlet.jsp.JspException
    • resolveFor

      protected String resolveFor() throws jakarta.servlet.jsp.JspException
      Determine the 'for' attribute value for this tag, autogenerating one if none specified.
      Throws:
      jakarta.servlet.jsp.JspException
      See Also:
    • autogenerateFor

      protected String autogenerateFor() throws jakarta.servlet.jsp.JspException
      Autogenerate the 'for' attribute value for this tag.

      The default implementation delegates to AbstractDataBoundFormElementTag.getPropertyPath(), deleting invalid characters (such as "[" or "]").

      Throws:
      jakarta.servlet.jsp.JspException
    • doEndTag

      public int doEndTag() throws jakarta.servlet.jsp.JspException
      Close the 'label' tag.
      Specified by:
      doEndTag in interface jakarta.servlet.jsp.tagext.Tag
      Overrides:
      doEndTag in class jakarta.servlet.jsp.tagext.TagSupport
      Throws:
      jakarta.servlet.jsp.JspException
    • doFinally

      public void doFinally()
      Disposes of the TagWriter instance.
      Specified by:
      doFinally in interface jakarta.servlet.jsp.tagext.TryCatchFinally
      Overrides:
      doFinally in class AbstractDataBoundFormElementTag