0

I've got a nasty problem with my Java Annotation:

@Pattern(regexp = "(...)", message = "(...) Tekst in Polish (...)")
    private String ip;

This is linked to my view using BindingResult and Thymeleaf:

<p th:if="${#fields.hasErrors('ip')}" class="error" th:errors="*{ip}"></p>

However, even though my entire page is in UTF-8 and text is displayed correctly, annotation is encoded improperly. I cannot reproduce it on my local machine, it happens only on my client's server. On both servers, file.encoding is equal to UTF-8. Thymeleaf configuration is set to use UTF-8 as well, Spring is configured to use UTF-8 too:

<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>
</filter>

How can I fix this issue? Thanks for all replies.

Solution: I moved the solution to another post below.

gczarnocki
  • 173
  • 1
  • 16

1 Answers1

0

Solution: This strange behaviour was caused by Gradle which was building my WAR in different encoding (in my case: different from UTF-8). I added: org.gradle.jvmargs='-Dfile.encoding=UTF-8' to my gradle.properties file (located at the same path as build.gradle - project root). Another solution is to add:

tasks.withType(JavaCompile) {
  options.encoding = 'UTF-8'
}

to build.gradle.

gczarnocki
  • 173
  • 1
  • 16