gist JS

Monday, April 16, 2007

Freemarker Spring

Sorry, another soporific blog post for those of you not building websites.

So you get:
freemarker.template.TemplateModelException: To do URL encoding, the framework that encloses FreeMarker must specify the output encoding or the URL encoding charset, so ask the programmers to fix it. Or, as a last chance, you can set the url_encoding_charset setting in the template, e.g. <#setting url_escaping_charset='ISO-8859-1'>, or give the charset explicitly to the buit-in, e.g. foo?url('ISO-8859-1').

And you feel bad about doing things described as "last chance" but where to specify freemarker variable in you spring config?

<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer" abstract="false"
singleton="true" lazy-init="default" autowire="default" dependency-check="default">
<property name="templateLoaderPath">
<property name="freemarkerSettings">
<prop key="datetime_format">MM/dd/yyyy</prop>
<prop key="number_format">0.#####</prop>
<prop key="url_escaping_charset">ISO-8859-1</prop>