Putting generated html code into a template

20 views
Skip to first unread message

Mat Jaggard

unread,
Jul 11, 2012, 9:19:16 AM7/11/12
to cambridge...@googlegroups.com
I have a template like this:

<!--$extends skeleton.html-->
<div id="bodyarea">
${myGeneratedCode}
</div>

and then I'm doing this in my Java code:

Template t = tempFactProv.get("admin/EditPageForm.html").createTemplate();
t.setProperty("myGeneratedCode ", getHTMLCode());
t.printTo(resp.getWriter());

but the HTML code I've generated is converted to &lt; etc. which has
been pretty useful in other places, but here I need to just send the
code directly. How can I do this?

Erdinc Yilmazel

unread,
Jul 11, 2012, 12:04:41 PM7/11/12
to cambridge...@googlegroups.com
Hi Mat,

Use %{myGeneratedCode} instead of ${myGeneratedCode}

See: https://code.google.com/p/cambridge/wiki/TemplateAuthorsGuide#Printing_object_values

Thanks,

Erdinc

Jon Stevens

unread,
Jul 11, 2012, 12:45:25 PM7/11/12
to cambridge...@googlegroups.com
Also, be 100% sure that you trust that HTML. ;-)

jon

Mat Jaggard

unread,
Jul 12, 2012, 9:25:16 AM7/12/12
to cambridge...@googlegroups.com
Great, thanks.

I'm doing the following, is this safe?

t.setProperty("myGeneratedCode", "<input name=\"static_name\"
value=\"" + EscapeFilter.doFilter(previouslySubmittedValue) + "\"/>");

Erdinc Yilmazel

unread,
Jul 12, 2012, 11:09:12 AM7/12/12
to cambridge...@googlegroups.com
It looks safe to me.

Jon Stevens

unread,
Jul 12, 2012, 12:22:26 PM7/12/12
to cambridge...@googlegroups.com
That is safe, but sane, I don't know. ;-) I try to keep that sort of html out of Java. I've found that spending a lot of effort to write java code to do tools like that is just a bad idea. What happens when you want to generate the form on the client side using something like handlebars? Or... what happens when you want your UX designer to work on the templates and they don't know anything about java?

jon

Mat Jaggard

unread,
Jul 12, 2012, 2:10:17 PM7/12/12
to cambridge...@googlegroups.com

Yeah, that's fair point. I'm doing a bit of a hack here I know.

Reply all
Reply to author
Forward
0 new messages