简体   繁体   English

在JSF中使用国际化时遇到的问题

[英]Problems while using Internationalization in JSF

I have a problem while trying to achieve Internationalization in JSF. 尝试在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). 当我在UI页面中输入某些数据(使用英语以外的其他语言)时,该值作为加密值存储在我的Managed Bean变量中(甚至无法确定该格式)。 I can't get the value as I entered it in my UI page. 在UI页面中输入值后,我无法获取该值。 I need to store the values of different languages(From JSF page) in my MySql Database. 我需要在MySql数据库中存储不同语言的值(来自JSF页面)。 But I am Struggling to get the Input values in Managed Bean as I stated above. 但是如上所述,我正在努力获取Managed Bean中的Input值。 Please guide me to do that. 请指导我这样做。

Thanks in Advance 提前致谢

Encrypted? 加密? You're kidding. 你在开玩笑。 Most likely you actually meant Mojibake . 您最有可能实际上是指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. 为了避免Mojibake,您需要确保在生成和使用字符时,在整个应用程序中使用相同的字符编码。 These days UTF-8 is a sane choice if you want world domination. 如今,如果您想统治世界,那么UTF-8是理智的选择。 JSF2 defaults to UTF-8 all the time already. JSF2一直一直默认为UTF-8。 So your problem is somewhat strange. 因此,您的问题有些奇怪。

Perhaps you're actually using PrimeFaces? 也许您实际上在使用PrimeFaces? It's known to mess the default UTF-8 character encoding when an ajax request is been fired. 触发ajax请求时,会破坏默认的UTF-8字符编码。 That part is answered here , you'd need to create a servlet filter. 在这里回答那部分,您需要创建一个servlet过滤器。

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? 还是该值实际上是正确的,但是您正在将该值打印到完全不支持UTF-8的输出中,因此您错误地确定了问题的原因? Eg via System.out.println() in Eclipse console. 例如,通过Eclipse控制台中的System.out.println() 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 . 或者,您可能通过<f:view encoding>显式地将JSF2编码强制更改为其他内容,例如ISO-8859-1 You should not do that, remove the encoding attribute from the <f:view> and keep it default. 您不应该这样做,请从<f:view>删除encoding属性并将其保留为默认值。

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. 或者很可能您的MySQL数据库/表编码根本不是UTF-8,但这与您描述的问题症状不符,或者您必须省略了实际打印从数据库检索到的值的部分,而不是从表单提交中检索的值。

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? 无论如何,您需要了解有关Java EE Web应用程序中字符编码的所有信息,包括所有可能出现的问题和解决方案,并以Unicode进行了详细说明-如何正确处理字符?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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