简体   繁体   中英

Problems while using Internationalization in JSF

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

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? Eg 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> , eg 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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM