utf-8 problem when using cambridge template in play framework

23 views
Skip to first unread message

shiarng li

unread,
Dec 30, 2011, 1:13:26 AM12/30/11
to Cambridge Template Engine
It works when running in play standalone model. But when i exported
application to a war, page coding problem happped. I checked the
code , and changed the code:
from
OutputStreamWriter out = new OutputStreamWriter(response.out);
to
OutputStreamWriter out = new
OutputStreamWriter(response.out,"UTF-8");

in file RenderCambridgeTemplate.java.

it acts.

can you adopt this change?

Erdinc Yilmazel

unread,
Dec 30, 2011, 10:44:59 AM12/30/11
to cambridge...@googlegroups.com
Sure, is utf-8 is the default/enforced character set in play? I am currently working on a play module for cambridge integration. With that new code, all Cambridge is responsible is rendering the template into a String and play takes care of writing to the output stream. So with this new module it shouldn't be a problem anymore. However if you want to stick to the way current play framework integration works, I can make this change as well.

Thanks,

Erdinc

Tom Carchrae

unread,
Dec 30, 2011, 10:56:57 AM12/30/11
to cambridge...@googlegroups.com
No, utf-8 is not the enforced encoding. This is how the Groovy
template gets the required encoding, stored in
currentResponse.encoding - the code uses ThreadLocal statics to
determine the current request/response. The variable
"_response_encoding" is the standard used in the default Play
templates.

(The __reponse_encoding variable causes issues with the 'smart' html
editor in eclipse when it sees the template contains an unknown
encoding called __response_encoding (mostly, I hate that part of
eclipse). I've not seen any way to disable the auto-detect of html
encoding either, which is a shame, bar some hacks of specifying the
encoding differently.)

// If current response-object is present, add _response_encoding'
Http.Response currentResponse = Http.Response.current();
if (currentResponse != null) {
binding.setVariable("_response_encoding", currentResponse.encoding);
}

Also, Erdinc, I would like to put some time to the Play module, but
I've been overloaded again. Sorry. I hope to have some proper time
soon.

Tom

Reply all
Reply to author
Forward
0 new messages