Spring Framework

org.springframework.web.servlet.tags.form
Class TagWriter

java.lang.Object
  extended by org.springframework.web.servlet.tags.form.TagWriter

public class TagWriter
extends java.lang.Object

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
TagWriter(javax.servlet.jsp.PageContext pageContext)
          Create a new instance of the TagWriter class that writes to the supplied PageContext.
TagWriter(java.io.Writer writer)
          Create a new instance of the TagWriter class that writes to the supplied Writer.
 
Method Summary
 void appendValue(java.lang.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 forceBlock()
          Indicate that the currently open tag should be closed and marked as a block level element.
 void startTag(java.lang.String tagName)
          Start a new tag with the supplied name.
 void writeAttribute(java.lang.String attributeName, java.lang.String attributeValue)
          Write an HTML attribute with the specified name and value.
 void writeOptionalAttributeValue(java.lang.String attributeName, java.lang.String attributeValue)
          Write an HTML attribute if the supplied value is not null or zero length.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TagWriter

public TagWriter(javax.servlet.jsp.PageContext pageContext)
Create a new instance of the TagWriter class that writes to the supplied PageContext.

Parameters:
pageContext - the JSP PageContext to obtain the Writer from

TagWriter

public TagWriter(java.io.Writer writer)
Create a new instance of the TagWriter class that writes to the supplied Writer.

Parameters:
writer - the Writer to write tag content to
Method Detail

startTag

public void startTag(java.lang.String tagName)
              throws javax.servlet.jsp.JspException
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:
javax.servlet.jsp.JspException
See Also:
endTag()

writeAttribute

public void writeAttribute(java.lang.String attributeName,
                           java.lang.String attributeValue)
                    throws javax.servlet.jsp.JspException
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:
java.lang.IllegalStateException - if the opening tag is closed
javax.servlet.jsp.JspException

writeOptionalAttributeValue

public void writeOptionalAttributeValue(java.lang.String attributeName,
                                        java.lang.String attributeValue)
                                 throws javax.servlet.jsp.JspException
Write an HTML attribute if the supplied value is not null or zero length.

Throws:
javax.servlet.jsp.JspException
See Also:
writeAttribute(String, String)

appendValue

public void appendValue(java.lang.String value)
                 throws javax.servlet.jsp.JspException
Close the current opening tag (if necessary) and appends the supplied value as inner text.

Throws:
java.lang.IllegalStateException - if no tag is open
javax.servlet.jsp.JspException

forceBlock

public void forceBlock()
                throws javax.servlet.jsp.JspException
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:
javax.servlet.jsp.JspException

endTag

public void endTag()
            throws javax.servlet.jsp.JspException
Close the current tag.

Correctly writes an empty tag if no inner text or nested tags have been written.

Throws:
javax.servlet.jsp.JspException

endTag

public void endTag(boolean enforceClosingTag)
            throws javax.servlet.jsp.JspException
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:
javax.servlet.jsp.JspException

Spring Framework