1

I have problem with setting proper charset on my jsf pages. I use MySql db with latin2 (ISO-8859-2 charset) and latin2_croatian_ci collation. But, I have problems with setting values on backing managed bean properties.

Page directive on top of my page is:

<%@ page language="java" pageEncoding="ISO-8859-2" contentType="text/html; charset=ISO-8859-2" %>

In head I included:

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-2">

And my form tag is:

<h:form id="entityDetails" acceptcharset="ISO-8859-2">

I've created and registered Filter in web.xml with following doFilter method implementation:

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    request.setCharacterEncoding("ISO-8859-2");
    response.setCharacterEncoding("ISO-8859-2");
    chain.doFilter(request, response);
}

But, i.e. when I set managed bean property through inputText, all special (unicode) characters are replaced with '?' character.

I really don't have any other ideas how to set charset to pages to perform well. Any suggestions?

Thanks in advance.

Tomas
  • 57,621
  • 49
  • 238
  • 373
Vladimir
  • 305
  • 1
  • 7
  • 16
  • 1
    *How* did you conclude that they are been corrupted? Did you review them in the view? Or in the stdout? (where you `System.out.print` those chars to). – BalusC Apr 18 '10 at 14:38
  • Sorry for my delay in response. I inserted some data through sql scripts into db, and they were displayed correctly, so I came to conclusion that displaying proper charset was not problem. I logged (stdout and file through slf4j) in backing bean set methods data sent from JSF, and data was already corrupted. Also, data inserted in database was corrupted. – Vladimir Apr 20 '10 at 15:36

1 Answers1

0

The logging I did was misleading. It turned out that stdout replaced special characters with '?' character. But, characters which were written to db were also replaced by '?' sign. The other part of the problem was that JConnector hasn't been set for correct encoding, so db entries looked very much like logged properties. I didn't realize that it was a combination of two problems.

Vladimir
  • 305
  • 1
  • 7
  • 16