Class TagWriter
java.lang.Object
org.springframework.web.servlet.tags.form.TagWriter
Utility class for writing HTML content to a
Writer
instance.
Intended to support output from JSP tag libraries.
- Since:
- 2.0
- Author:
- Rob Harrop, Juergen Hoeller
-
Constructor Summary
ConstructorDescriptionTagWriter
(PageContext pageContext) Create a new instance of theTagWriter
class that writes to the suppliedPageContext
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
appendValue
(String value) Close the current opening tag (if necessary) and appends the supplied value as inner text.void
endTag()
Close the current tag.void
endTag
(boolean enforceClosingTag) Close the current tag, allowing to enforce a full closing tag.void
Indicate that the currently open tag should be closed and marked as a block level element.void
Start a new tag with the supplied name.void
writeAttribute
(String attributeName) Variant ofwriteAttribute(String, String)
for writing empty HTML attributes without a value such asrequired
.void
writeAttribute
(String attributeName, String attributeValue) Write an HTML attribute with the specified name and value.void
writeOptionalAttributeValue
(String attributeName, String attributeValue) Write an HTML attribute if the supplied value is notnull
or zero length.
-
Constructor Details
-
TagWriter
Create a new instance of theTagWriter
class that writes to the suppliedPageContext
.- Parameters:
pageContext
- the JSP PageContext to obtain theWriter
from
-
TagWriter
- Parameters:
writer
- theWriter
to write tag content to
-
-
Method Details
-
startTag
Start a new tag with the supplied name. Leaves the tag open so that attributes, inner text or nested tags can be written into it.- Throws:
JspException
- See Also:
-
writeAttribute
Write an HTML attribute with the specified name and value.Be sure to write all attributes before writing any inner text or nested tags.
- Throws:
IllegalStateException
- if the opening tag is closedJspException
-
writeAttribute
Variant ofwriteAttribute(String, String)
for writing empty HTML attributes without a value such asrequired
.- Throws:
JspException
- Since:
- 5.3.14
-
writeOptionalAttributeValue
public void writeOptionalAttributeValue(String attributeName, @Nullable String attributeValue) throws JspException Write an HTML attribute if the supplied value is notnull
or zero length.- Throws:
JspException
- See Also:
-
appendValue
Close the current opening tag (if necessary) and appends the supplied value as inner text.- Throws:
IllegalStateException
- if no tag is openJspException
-
forceBlock
Indicate that the currently open tag should be closed and marked as a block level element.Useful when you plan to write additional content in the body outside the context of the current
TagWriter
.- Throws:
JspException
-
endTag
Close the current tag.Correctly writes an empty tag if no inner text or nested tags have been written.
- Throws:
JspException
-
endTag
Close the current tag, allowing to enforce a full closing tag.Correctly writes an empty tag if no inner text or nested tags have been written.
- Parameters:
enforceClosingTag
- whether a full closing tag should be rendered in any case, even in case of a non-block tag- Throws:
JspException
-