休眠验证器+ jsf 2.0:UTF-8中的ValidationMessages.properties [英] hibernate validator + jsf 2.0: ValidationMessages.properties in UTF-8
问题描述
我在UTF-8中显示Hibernate Validator的自定义ValidationMessages时遇到问题.
I have a problem with displaying custom ValidationMessages of Hibernate Validator in UTF-8.
For common jsf messages I followed this advice: i18n with UTF-8 encoded properties files in JSF 2.0 appliaction - I created class Text and used it in faces-config.xml. This is working properly.
但是这种方法不适用于ValidationMessages. UTF-8中不显示特殊字符.
But this approach is not working with ValidationMessages; special characters are not displayed in UTF-8.
有人可以给我一些建议吗?非常感谢
Could anyone give me some advice about this? Thank you very much
推荐答案
如果您使用与 https://stackoverflow.com/a/3646601/5072526 ,您可以执行以下操作:
If you use the same Resource-Bundle like in https://stackoverflow.com/a/3646601/5072526, you can do this:
根据该答案修改ResourceBundle,因此您还有一个附加的构造方法,该构造方法采用语言环境:
Modify the ResourceBundle from that answer, so you have an additional Constructor, that takes a locale:
public I18NUtf8RessourceBundle(Locale locale) {
setParent(ResourceBundle.getBundle(BUNDLE_NAME,
locale, UTF8_CONTROL));
}
然后在默认包中创建一个类ValidationMessages
:
Then create a Class ValidationMessages
in the default package:
public class ValidationMessages extends I18NUtf8RessourceBundle{
public ValidationMessages() {
super(null);
}
}
然后使用特定的语言环境(_en,_de等)创建相同的类:
Then make the same Class with a specific Locale (_en, _de, etc.):
public class ValidationMessages_en extends I18NUtf8RessourceBundle{
public ValidationMessages_en() {
super(Locale.ENGLISH);
}
}
对所有语言执行相同操作,并每次传递不同的语言环境:
Do the same for all your Languages and pass a different Locale each time:
有了它,它就可以工作了,您甚至可以拥有与普通翻译相同的验证消息文件!
With that, it works, you can even have the same File for the Validation Messages as for the normal translations!
这篇关于休眠验证器+ jsf 2.0:UTF-8中的ValidationMessages.properties的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!