Search code examples
grailsencodingutf-8character-encodinggsp

Grails encoding non UK characters from GSP to Controller


I've got a Grails (2.0.4) application, all setted up to manage UTF-8 encoding (meta tag in the layout, mysql database tables). Unfortunately, something strange happens.

For example, if in a form (to create a domain instance) I type any text containing non-UK characters, like this:

más que nada

the POST contains the exact text (with the "á" character as is) but the params variable in the controller contains the wrong text:

más que nada

There's nothing between the view and the controller, how can this happen?

I also tried, without good results, to set in Config.groovy:

grails.views.default.codec = "html"

Is there something else I'm missing to set up?

Thanks in advance to everyone who will take the time to have a look at this issue.


Solution

  • I'm sorry, I figured out what the problem was days ago but I hadn't time to answer my own question till now.

    Unfortunately I forgot to mention a key part of the problem, because I didn't thought it was related. I got the encoding problem only on AJAX call, and I didn't mention it because all savings in my application are done through AJAX.

    So, the encoding problem was related to the configuration of the content type of the jQuery post, which (to work properly with UTF-8) has to be like this:

    contentType: "application/x-www-form-urlencoded;charset=UTF-8"