Render Element into String ?

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

Render Element into String ?

Jan Goyvaerts
A not so common use case I'm afraid: Put an html fragment into an element attribute. For example:

<a href="#" content="<div>....</div>"/>

I've got the Element object for the "content" attribute, but I'm don't know how to get it resolved into a single String value.

I've tried DomUtils.getHtml5For(Node). It does produce the markup; to the exception of custom tags. Those remain unprocessed.

DOMUtils.getOutputFor(....) gives the same result.

Is there something else I need to set to get the custom tags/attributes processed too ?

THX !

Jan
Reply | Threaded
Open this post in threaded view
|

Re: Render Element into String ?

Zemi
Administrator
Have you tried th:attr?
         

Reply | Threaded
Open this post in threaded view
|

Re: Render Element into String ?

Jan Goyvaerts
Yep: org.thymeleaf.dom.Element@379faa8c :-)
Reply | Threaded
Open this post in threaded view
|

Re: Render Element into String ?

Jan Goyvaerts
Presumably the problem is that it doesn't know about the template resolver & co - the Configuration. So it has no means to resolve custom markup.
Reply | Threaded
Open this post in threaded view
|

Re: Render Element into String ?

Zemi
Administrator
Sorry, I missed the part where you said that the contents where not processed.

If you want to process contents you would have to inkove the TemplateEngine yourself like in the following code (line 30):
    http://sourceforge.net/p/html5valdialect/code/HEAD/tree/trunk/core/src/test/java/integration/IntegrationTestBase.java
Reply | Threaded
Open this post in threaded view
|

Re: Render Element into String ?

Jan Goyvaerts
That would certainly work; the problem is that the Element object is only a fragment. Hence neither is there is a template file for it.

It's simple an Element instance residing in memory.
Reply | Threaded
Open this post in threaded view
|

Re: Render Element into String ?

Jan Goyvaerts
Is there a way to resolve a String value/Reader/Inputstream instead of the content of a file ?