Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Requirements for Using

...

UTF-8

NOTE: Use any OpenMRS version 1.6 and beyond.  These version have also been fixed:  1.5.1, 1.4 Beta 2 (aka 1.4.0.22), or 1.3.4 (See ticket:965, ticket:365, ticket:1539, ticket:1943 for updates)

Modify Hibernate Database Connection URL

Modify the database URL connection so it would know that we're passing UTF-8 char.

...

Code Block
connection.url=jdbc:mysql://localhost:3306/openmrs_test?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8

Modify Tomcat Server Configuration

From Tomcat UTF-8

Modify Tomcat's server.xml file and add the following attribute to the connector tag:

...

Code Block
<Connector port="8080" maxHttpHeaderSize="8192" ... URIEncoding="UTF-8" />

Modify MySQL configuration

From MySQL: Configuring the Character Set

...

Code Block
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci

For interested developers

These are the changes we had to make to our code:

Modify OpenMRS Web Configuration

Added the following line to OpenMRS web.xml:

Code Block
<filter>
<filter-name>charsetFilter</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>charsetFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

Modify OpenMRS Header File

Added the following as the first line in headerFull.jsp and headerMinimal.jsp:<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>

Check the current setting

To confirm the current character set, modify maintenance/systemInfo.jsp by adding these lines:

Code Block
<tr>
<td>Default Locale</td>
<td><%= java.nio.charset.Charset.defaultCharset() %></td>
</tr>

Modified Controller to make correct urls

Modify the AddPersonController.java: 23

Fromreturn "?addName=" + name + ...
Toreturn "?addName=" + URLEncoder.encode(name, "UTF-8") + ...
Notice the "name" needs to be explicitly encoded because the function will return the redirection URL to the client. Other similar pattern will also need to be encoded as necessary.

Messages.properties files

You can now directly put unicode characters into messages_XX.properties. You no longer have to type unicode codes into strings (remember how these files used to be full of \u00E9, for example?). The key, however, is to make sure that your file editor encodes the messages_XX.properties file using UTF-8. If you open messages_fr.properties in eclipse, and you see garbage, change the default character encoding of your editor, or try a different application like Notepad++, if necessary.

java.util.Properties

The java Properties class has two methods (load() and store()) that don't support UTF-8, that were used in a couple of places, most notably when loading message string files. There are now alternate methods that you can use in OpenmrsUtil that preform the same function, but read and write using UTF-8.