1

When I try to add an offer in the Broadleaf Admin, euro signs (€) in the name or description are converted into ⬠after saving.

The strange thing about this is that this behaviour does not occur when saving a code for this offer. For example:

  • I create a promo called "€5 promo"
  • After saving I'll get: â¬5 promo (bad)
  • I add a code to this promo called "€5 code"
  • After saving it will look like this: €5 code (good)

I thing it has something to do with the saving, because when I modify the field in the database, it displays correctly. When I try to edit it and save the strange symbols take over again...

EDIT 1

JerryOz was very close to the solution. The only thing I needed to add (next to his solution) was the code below to my web.xml:

<filter>
    <filter-name>encodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
Frederik Voordeckers
  • 1,321
  • 15
  • 31

1 Answers1

2

The issue is that the app is not encoding correctly when it goes to the database. If you are using Tomcat, add connectionPropeties to your Resources in context.xml. This will encode to UTF-8 and allow the special characters to be saved correctly in the DB. Here's a sample:

<Resource name="jdbc/web" auth="Container" type="javax.sql.DataSource"
           maxActive="30" maxIdle="60" maxWait="10000"
           username="username" password="password" driverClassName="com.mysql.jdbc.Driver"
           connectionProperties="useUnicode=true;characterEncoding=utf8;"
           url="jdbc:mysql://localhost/broadleaf"/>

You'll also want to configure your Connectors with URIEncoding="UTF-8" in server.xml to make sure the GET request parameters get encoded correctly. This will allow filtering on names with the special characters in the admin. Here's a sample:

<Connector port="8080" protocol="HTTP/1.1"
          connectionTimeout="20000"
          redirectPort="8443" 
          URIEncoding="UTF-8"/>

This is related to this great answer below which covers UTF-8 in java webapps:

How to get UTF-8 working in Java webapps?

Hope this helps!

Community
  • 1
  • 1
JerryOz
  • 116
  • 2