休眠验证器+ jsf 2.0:UTF-8中的ValidationMessages.properties [英] hibernate validator + jsf 2.0: ValidationMessages.properties in UTF-8

查看:132
本文介绍了休眠验证器+ jsf 2.0:UTF-8中的ValidationMessages.properties的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UTF-8中显示Hibernate Validator的自定义ValidationMessages时遇到问题.

I have a problem with displaying custom ValidationMessages of Hibernate Validator in UTF-8.

对于常见的jsf消息,我遵循以下建议:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆