Class ErrorsTag

All Implemented Interfaces:
jakarta.servlet.jsp.tagext.BodyTag, 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 ErrorsTag extends AbstractHtmlElementBodyTag implements jakarta.servlet.jsp.tagext.BodyTag
The <errors> tag renders field errors in an HTML 'span' tag. Displays errors for either an object or a particular field.

This tag supports three main usage patterns:

  1. Field only - set 'path' to the field name (or path)
  2. Object errors only - omit 'path'
  3. All errors - set 'path' to '*'

Attribute Summary

Attribute Required? Runtime Expression? Description

cssClass

false

true

HTML Optional Attribute

cssStyle

false

true

HTML Optional Attribute

delimiter

false

true

Delimiter for displaying multiple error messages. Defaults to the br tag.

dir

false

true

HTML Standard Attribute

element

false

true

Specifies the HTML element that is used to render the enclosing errors.

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

false

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, Rick Evans
See Also:
  • Field Details

    • MESSAGES_ATTRIBUTE

      public static final String MESSAGES_ATTRIBUTE
      The key under which this tag exposes error messages in the page context scope.
      See Also:
    • SPAN_TAG

      public static final String SPAN_TAG
      The HTML 'span' tag.
      See Also:
  • Constructor Details

    • ErrorsTag

      public ErrorsTag()
  • Method Details

    • setElement

      public void setElement(String element)
      Set the HTML element must be used to render the error messages.

      Defaults to an HTML '<span/>' tag.

    • getElement

      public String getElement()
      Get the HTML element must be used to render the error messages.
    • setDelimiter

      public void setDelimiter(String delimiter)
      Set the delimiter to be used between error messages.

      Defaults to an HTML '<br/>' tag.

    • getDelimiter

      public String getDelimiter()
      Return the delimiter to be used between error messages.
    • autogenerateId

      protected String autogenerateId() throws jakarta.servlet.jsp.JspException
      Get the value for the HTML 'id' attribute.

      Appends '.errors' to the value returned by AbstractDataBoundFormElementTag.getPropertyPath() or to the model attribute name if the <form:errors/> tag's 'path' attribute has been omitted.

      Overrides:
      autogenerateId in class AbstractDataBoundFormElementTag
      Returns:
      the value for the HTML 'id' attribute
      Throws:
      jakarta.servlet.jsp.JspException
      See Also:
    • getName

      protected @Nullable String getName() throws jakarta.servlet.jsp.JspException
      Get the value for the HTML 'name' attribute.

      Simply returns null because the 'name' attribute is not a validate attribute for the 'span' element.

      Overrides:
      getName in class AbstractDataBoundFormElementTag
      Returns:
      the value for the HTML 'name' attribute
      Throws:
      jakarta.servlet.jsp.JspException
    • shouldRender

      protected boolean shouldRender() throws jakarta.servlet.jsp.JspException
      Should rendering of this tag proceed at all?

      Only renders output when there are errors for the configured path.

      Overrides:
      shouldRender in class AbstractHtmlElementBodyTag
      Returns:
      true only when there are errors for the configured path
      Throws:
      jakarta.servlet.jsp.JspException
    • renderDefaultContent

      protected void renderDefaultContent(TagWriter tagWriter) throws jakarta.servlet.jsp.JspException
      Specified by:
      renderDefaultContent in class AbstractHtmlElementBodyTag
      Throws:
      jakarta.servlet.jsp.JspException
    • exposeAttributes

      protected void exposeAttributes() throws jakarta.servlet.jsp.JspException
      Exposes any bind status error messages under this key in the PageContext.PAGE_SCOPE.

      Only called if shouldRender() returns true.

      Overrides:
      exposeAttributes in class AbstractHtmlElementBodyTag
      Throws:
      jakarta.servlet.jsp.JspException
      See Also:
    • removeAttributes

      protected void removeAttributes()
      Removes any bind status error messages that were previously stored under this key in the PageContext.PAGE_SCOPE.
      Overrides:
      removeAttributes in class AbstractHtmlElementBodyTag
      See Also: