Problem with euro symbol

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

Problem with euro symbol

Zemi
Administrator
Hi,

I am using the euro symbol (€) inside a template, and the euro symbol appears in the output HTML as a '?'.

My templates use UTF-8 encoding and I have set the templateResolver.characterEncoding property to "UTF-8".

I also tried modifying the template 'seedstartermng.html' of the Spring Thymeleaf example (thymeleafexamples-stsm) and the problem arose too.

Other non-ascii characters like 'á', 'è', 'ñ' are displayed properly.
Reply | Threaded
Open this post in threaded view
|

Re: Problem with euro symbol

Zemi
Administrator
The problem also happens when the euro symbol comes from a i18n properties file

   < span th:text="#{euroMessage}" >

but it does not happen when the symbol comes from a Java object

   < span th:text="${euroObject}" >

Reply | Threaded
Open this post in threaded view
|

Re: Problem with euro symbol

danielfernandez
Administrator
Hi,

Are you sure your template is correctly encoded in UTF-8? sometimes, editors do not correctly encode file modifications and can include byte sequences in ISO-8859-1 into UTF-8 files... could it be that you have mixed encodings in the same file?

And also, have you checked the encoding you are using for HTML output? Could it be that the browser is being sent your HTML as ISO-8859-1 (which does NOT include an EURO symbol) instead of ISO-8859-15 (which does)? If so, switching your HTML output to UTF-8 or ISO-8859-15 (including both Spring MVC and <meta> tags) should make your euro symbols appear...


Regards,
Daniel.
Reply | Threaded
Open this post in threaded view
|

Re: Problem with euro symbol

danielfernandez
Administrator

Also, please note that the Java SE specification establishes that .properties files must ALWAYS be encoded in ISO-8859-1, whichever the host Operating System, and that any character not in the ISO-8859-1 char set should be specified in the form of a unicode escape.

So, in a .properties file you should always specify your euro symbols as "\u20ac"

Regards,
Daniel
Reply | Threaded
Open this post in threaded view
|

Re: Problem with euro symbol

Zemi
Administrator
Hello,

you were right, it was a configuration issue.

I had to set "characterEncoding" parameter to the ViewResolver (Spring configuration):

    <bean id="viewResolver" class="org.thymeleaf.spring3.view.ThymeleafViewResolver">
        <property name="templateEngine" ref="templateEngine" />
        <property name="characterEncoding" value="UTF-8" />
    </bean>

Thank you very much for your help.