Class AbstractFormTag

java.lang.Object
jakarta.servlet.jsp.tagext.TagSupport
All Implemented Interfaces:
jakarta.servlet.jsp.tagext.IterationTag, jakarta.servlet.jsp.tagext.JspTag, jakarta.servlet.jsp.tagext.Tag, jakarta.servlet.jsp.tagext.TryCatchFinally, Serializable
Direct Known Subclasses:
AbstractDataBoundFormElementTag

public abstract class AbstractFormTag extends HtmlEscapingAwareTag
Base class for all JSP form tags. Provides utility methods for null-safe EL evaluation and for accessing and working with a TagWriter.

Subclasses should implement the writeTagContent(TagWriter) to perform actual tag rendering.

Subclasses (or test classes) can override the createTagWriter() method to redirect output to a Writer other than the JspWriter associated with the current PageContext.

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

    • AbstractFormTag

      public AbstractFormTag()
  • Method Details

    • evaluate

      protected @Nullable Object evaluate(String attributeName, @Nullable Object value) throws jakarta.servlet.jsp.JspException
      Evaluate the supplied value for the supplied attribute name.

      The default implementation simply returns the given value as-is.

      Throws:
      jakarta.servlet.jsp.JspException
    • writeOptionalAttribute

      protected final void writeOptionalAttribute(TagWriter tagWriter, String attributeName, @Nullable String value) throws jakarta.servlet.jsp.JspException
      Optionally writes the supplied value under the supplied attribute name into the supplied TagWriter. In this case, the supplied value is evaluated first and then the String representation is written as the attribute value. If the resultant String representation is null or empty, no attribute is written.
      Throws:
      jakarta.servlet.jsp.JspException
      See Also:
    • createTagWriter

      protected TagWriter createTagWriter()
      Create the TagWriter which all output will be written to. By default, the TagWriter writes its output to the JspWriter for the current PageContext. Subclasses may choose to change the Writer to which output is actually written.
    • doStartTagInternal

      protected final int doStartTagInternal() throws Exception
      Provide a simple template method that calls createTagWriter() and passes the created TagWriter to the writeTagContent(TagWriter) method.
      Specified by:
      doStartTagInternal in class RequestContextAwareTag
      Returns:
      the value returned by writeTagContent(TagWriter)
      Throws:
      Exception - any exception, any checked one other than a JspException gets wrapped in a JspException by doStartTag
      See Also:
      • TagSupport.doStartTag()
    • getDisplayString

      protected String getDisplayString(@Nullable Object value)
      Get the display value of the supplied Object, HTML escaped as required. This version is not PropertyEditor-aware.
    • getDisplayString

      protected String getDisplayString(@Nullable Object value, @Nullable PropertyEditor propertyEditor)
      Get the display value of the supplied Object, HTML escaped as required. If the supplied value is not a String and the supplied PropertyEditor is not null then the PropertyEditor is used to obtain the display value.
    • isDefaultHtmlEscape

      protected boolean isDefaultHtmlEscape()
      Overridden to default to true in case of no explicit default given.
      Overrides:
      isDefaultHtmlEscape in class HtmlEscapingAwareTag
      See Also:
    • writeTagContent

      protected abstract int writeTagContent(TagWriter tagWriter) throws jakarta.servlet.jsp.JspException
      Subclasses should implement this method to perform tag content rendering.
      Returns:
      valid tag render instruction as per Tag.doStartTag().
      Throws:
      jakarta.servlet.jsp.JspException