I have a Tapestry application, that retrieves data from a form, writes it to a database and then displays the result. It all works well as long as no special characters (Ä, Ö, Ü, ß, € ...) are used.
E.g. the text
TestäöüßÄÖÜ€$
will result in
TestäöüÃÃÃÃâ¬$
I guess the problem has something to do with a wrong character encoding setting.
Tapestry java class:
@Component(parameters = {"clientValidation=false"})
private Form form;
@Component(parameters = {"value=someDTO.name"})
private TextField someNameField;
Tapestry Template:
<t:form t:id="form">
...
<t:textfield t:id="someNameField"/>
...
</t:form>
I checked my encoding settings at several places:
- HTML source:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
Tapestry settings (this should be the default anyway):
tapestry.charset=UTF-8
Firefox says (Tools>Page Info: Encoding): UTF-8.
The underlying database (Oracle) also uses UTF-8:
character_set_system utf8
Then I examined the header of the POST request and two things caught my eye:
There is no content type specified in the header. I would expect something like this:
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Spaces are encoded with + instead of %20.
I also tried the following:
@Component(parameters = {"clientValidation=false", "enctype='application/x-www-form-urlencoded; charset=UTF-8'"})
private Form form;
and
@Component(parameters = {"clientValidation=false", "enctype='application/x-www-form-urlencoded; charset=UTF-8'", "accept-charset='utf-8'"})
private Form form;
but both with no success (and I'm looking for a general solution not a workaround).
Interestingly this proposal works for some special chars (like ä, ö, ü, ß and so on), but I do not want to use ISO-8859-1. How can I set the encoding Tapestry uses for forms to UTF-8? What am I missing or is there a completely different reason for my problem?
EDIT: I made a test without the database and the problem remains, so it's not about a wrong encoding setting on the db-side.
It was indeed a misconfiguration of my server. The following addition to my web.xml solved it (of course this should also work with a non-Spring filter).
I have tried your test string in Tapestry 5.2.6 and 5.3.0-SNAPSHOT and it worked fine. I was able to persist it to the HSQLDB database and pull it back out as expected.
What version are you using? If you are back in 5.0.x you may need to do something like this: http://wiki.apache.org/tapestry/Tapestry5Utf8Encoding