Configurable OutputHandler

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Configurable OutputHandler

Grzegorz Grzybek
Hi

Probably the last thing, that let me say Thymeleaf has replaced JSP is the way of using freeform Thymeleaf fragments.
Tymeleaf provides th:include attribute, but is there a way of rendering output which doesn't have "html" as root attribute? Of course there is but not quite perfect.
I have fragment:

[code]
<div xmlns:th="http://www.thymeleaf.org">
        < span th:utext="${now}">now</ span>
</div>
[/code]

and I want to use it as a result of invokng AJAX method (to simply insert it somewhere using innerHTML, or jQuery's html()). But there's problem:
 - if I use XHTML/HTML5/LEGACYHTML5 mode it requires DOCTYPE declaration
 - if I use XML/VALIDXML mode, it results in:

[code]
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<div>
        < span>Mon Nov 07 09:09:47 CET 2011</ span>
</div>
[/code]

Unfortunately TemplateMode is enum and I can't extend it.
I'd like to user XML mode for fragments and XHTML mode for "root" templates (for entire pages) - the main problem is that OutputHandler's output() method uses:

[code]
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no")
[/code]

and output() is invoked statically from org.thymeleaf.TemplateEngine.process()...

Summarizing, my requirements are:
 - clean, beautiful template engine: checked
 - natural templating: checked
 - SpringMVC integration: checked
 - DOCTYPE translation: checked
 - fragments: almost - the problem is I want to be able to use both XHTML/HTML5 mode (for pages) and XML mode (for fragments used in AJAX responses).

regards
Grzegorz Grzybek
Reply | Threaded
Open this post in threaded view
|

Re: Configurable OutputHandler

Zemi
Administrator
Hi Grzegorz,

please take a look at this post
    http://forum.thymeleaf.org/response-only-body-elements-td3445202.html

maybe the provided solution could fit your needs.
Reply | Threaded
Open this post in threaded view
|

Re: Configurable OutputHandler

Grzegorz Grzybek
Hi

Thanks for reply! I've seen this thread and read about $.load(), but I have a little mental blockade with:
[quote]
... but then jQuery parses the returned document to find the element with an ID of container ...
[/quote]

I know it's really fast, but...

What in practice is convincing me is that writing full (with html and body elements) templates and loading only portions of them is still "natural templating" - you can open them in browser and see the final look.

However - one tiny more enum in TemplateMode (which doesn't require doctype and which won't produce XML declaration) should not harm anybody ;)

Thanks again!
Grzegorz Grzybek