Interface MarkupWriter

  • All Known Subinterfaces:
    MarkupBuilderWriter
    All Known Implementing Classes:
    HtmlWriter

    public interface MarkupWriter
    Wrap builders for deferred writing.

    This is useful when you want to define the markup but do not have the Writer yet.

    Often this is the case when:

    • MVC framework (such as Spring MVC) where the writer is not available till rendering time.
    • Composition of builders.
    You can achieve functional composition of markup builders by creating methods that return MarkupWriters.
            private HtmlWriter createInput(final String name, final String value) {
                    return new HtmlWriter() {
                            protected void build() {
                                    input().name(name).value(value).end();
                            }
                    };
            }
            
            private HtmlWriter createForm(final HtmlWriter ... inputs) {
                    return new HtmlWriter() {
                            protected void build() {
                                    form().write(inputs).end();
                            }
                    };
            }
     
    See MarkupBuilder.write(MarkupWriter...)

    See Also:
    HtmlWriter, MarkupBuilder.write(MarkupWriter...)
    • Method Detail

      • write

        <W extends java.io.Writer> W write​(W writer)
        Writes using the given writer. The writer should not be closed and will not be closed by implementations. Its up to the caller to close the writer.
        Type Parameters:
        W - writer type.
        Parameters:
        writer - not null.
        Returns:
        the writer used for fluent style.