views:

578

answers:

1

Hi there,

last week I asked a question but JSF and charset encoding

relevant SO question

Now I included this JSF in my JBoss Portal env. with the common jboss portlet bridge. When I submit my form something weird happens:

The portal is UTF-8 so my form inputs are UTF-8 too but after the submit the chars are encoded as UTF-8 again which causes something like this

äöü

If the response page is submitted again it turns into this

äöü

You can hit the submit button and see the chars getting encoded everytime again.

Is this working as intended?

+1  A: 

This will happen when the data which is initially decoded using UTF-8 has been incorrectly encoded using ISO-8859-1. You can easily reproduce this by:

String input1 = new String("äöü");
System.out.println(input1); // äöü
String input2 = new String(input1.getBytes("UTF-8"), "ISO-8859-1");
System.out.println(input2); // äöü
String input3 = new String(input2.getBytes("UTF-8"), "ISO-8859-1");
System.out.println(input3); // äöü

(note that the last one actually contains more characters, but SO's message parser ate them).

This means that somewhere in your webapp ISO-8859-1 was incorrectly been used instead of UTF-8. It's hard to pinpoint the root cause with the as far given information. You can try to sysout the request parameters in the JSF bean action method and read the output in stdout (you only need to ensure that the stdout is using UTF-8 as well! if you're using an IDE like Eclispe, you can configure that in Workspace preferences). If those chars looks garbage as well, then it's the request encoding which is wrong. If those chars looks fine, then it's the response or webbrowser encoding which is wrong. To exclude the webbrowser from being suspect, then you can in e.g. Firefox determine the encoding used by View > Character Encoding.

BalusC
I've changed my logging to debug and enabled my jboss to log every request. It seems that the chars are corrupt after my submit, the log shows the unicode chars only as ????.I'm using a JBoss 4.2.3 Server atm.
asrijaal
The logger needs to be configured to use `UTF-8`. This is not per-se the root cause of this particular problem however. Reread the article to **understand** the bits about character encoding.
BalusC