0

I have a problem while trying to achieve Internationalization in JSF. When I enter some data in my UI Page (in lang other than English), that value is stored in my Managed Bean variable as an encrypted value(can't even Identify what format is that). I can't get the value as I entered it in my UI page. I need to store the values of different languages(From JSF page) in my MySql Database. But I am Struggling to get the Input values in Managed Bean as I stated above. Please guide me to do that.

Thanks in Advance

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Arun
  • 825
  • 4
  • 14
  • 31

1 Answers1

4

Encrypted? You're kidding. Most likely you actually meant Mojibake.

In order to avoid Mojibake, you need to ensure that you use the one and the same character encoding throughout your entire application while producing and consuming characters. These days UTF-8 is a sane choice if you want world domination. JSF2 defaults to UTF-8 all the time already. So your problem is somewhat strange.

Perhaps you're actually using PrimeFaces? It's known to mess the default UTF-8 character encoding when an ajax request is been fired. That part is answered here, you'd need to create a servlet filter.

Or perhaps the value is actually correct, but you're printing the value to an output which does not support UTF-8 at all and thus you incorrectly identified the cause of the problem? E.g. via System.out.println() in Eclipse console. You'd need to configure it via Window > Preferences > General > Workspace > Text file encoding as answered here.

Or perhaps you explicitly forced the JSF2 encoding to something different by <f:view encoding>, e.g. to ISO-8859-1. You should not do that, remove the encoding attribute from the <f:view> and keep it default.

Or very perhaps your MySQL DB/table encoding is not UTF-8 at all, but that would not match the problem symptoms you described, or you must have omitted the part that you're actually printing the value retrieved from the DB instead of the value retrieved from the form submit.

In any case, everything you need to know about character encoding in Java EE web applications, complete with all possible problems and solutions is elaborated in Unicode - How to get the characters right?

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks for answer BalusC. I am getting like this "விà®à®¯à¯" when I enter some value and I tried to save it in DB – Arun Feb 05 '13 at 12:52
  • Yes, I understood that. Do you understand the answer and have applied the fixes? – BalusC Feb 05 '13 at 12:54
  • In my page., I have no AJAX call and f:view.. and I tried that Text File Encoding also... Nothing worked out. and mytable supports UTF-8. Now I am reading your blog to get the characters right. – Arun Feb 05 '13 at 13:00
  • Oh, I should perhaps mention that I assume that you're using Facelets and not its deprecated predecesor JSP. You see, you've tagged the question with `[jsf2]`. But if you're -completely unexpectedly- actually using JSP, then you should set the page encoding (or better, dump it and replace by Facelets). – BalusC Feb 05 '13 at 13:03
  • I am using primefaces in JSF.. BTW now my values saved in DB as I entered(in other languages) only in the second submit. When I submit after entering the values it saved in DB as Mojibake :( – Arun Feb 07 '13 at 09:19
  • Yes. Have you applied the fixes mentioned in the answer? E.g. the filter. – BalusC Feb 07 '13 at 10:36
  • Yes BalusC.. Now its Working fine.. I have used filter to resolve.. Thanks a lot BalusC :) – Arun Feb 07 '13 at 11:54