首页 > 解决方案 > face-config 默认需要消息覆盖编码

问题描述

我有一个使用多种语言的多语言项目,我创建了一个 UTF8-Control,我在我的 face-config.xml 中定义,它适用于所有语言的 .properties 文件。

然后我覆盖 javax.faces.component.UIInput.REQUIRED = {0} wird benötigt。在 UI 中,当我需要德语所需的消息时,我会收到名称 wird benötigt。

仅当我尝试使用自定义消息覆盖时才会出现此问题

javax.faces.component.UIInput.CONVERSION javax.faces.converter.DateTimeConverter.DATE_detail

这给我的印象是我的 UT8Control 没有用于转换此文本(当我尝试调试时也是如此)

我的 UTF8Control 类在这里

public class UTF8Control extends ResourceBundle.Control {
@Override
public ResourceBundle newBundle
    (String baseName, Locale locale, String format, ClassLoader loader, boolean reload)
        throws IllegalAccessException, InstantiationException, IOException
{
    // The below is a copy of the default implementation.
    String bundleName = toBundleName(baseName, locale);
    String resourceName = toResourceName(bundleName, "properties");
    ResourceBundle bundle = null;
    InputStream stream = null;
    if (reload) {
        URL url = loader.getResource(resourceName);
        if (url != null) {
            URLConnection connection = url.openConnection();
            if (connection != null) {
                connection.setUseCaches(false);
                stream = connection.getInputStream();
            }
        }
    } else {
        stream = loader.getResourceAsStream(resourceName);
    }
    if (stream != null) {
        try {
            // Only this line is changed to make it to read properties files as UTF-8.
            bundle = new PropertyResourceBundle(new InputStreamReader(stream, UTF_8));
        } finally {
            stream.close();
        }
    }
    return bundle;
}

@Override
public Locale getFallbackLocale(String name,
                                        Locale locale) {
    // see super @return description. Return null for no fallback locale
    return null;
}}

标签: javaspring-bootjsfprimefacesicefaces

解决方案


推荐阅读