开发者

JSF FacesMessage localization

My problem now is that I can't get localization working with FacesMessage

I've tried:

try {
    ResourceBundle bundle = ResourceBundle.getBundle("translations", context.getViewRoot().getLocale());
    text = bundle.getString("loginFail");
} catch (Exception e) {
    System.out.println("EXCEPTION: " + e);
}

FacesContext.getCurrentInstance().addMessage("", new FacesMessage(text));

but the following exception is thrown

java.util.MissingResourceException: Can't find bundle for base name translations, locale cs

faces-config.xml contains:

<application>
    <locale-开发者_如何转开发config>
        <default-locale>cs</default-locale>
        <supported-locale>en</supported-locale>
    </locale-config>
    <resource-bundle>
        <base-name>tr.translations</base-name>
        <var>txt</var>
    </resource-bundle>
    <message-bundle>
        tr.translations
    </message-bundle>
</application>

Files translations_cs.properties and translations_en.properties are in the tr package, the location is definitely ok.

Do you have any idea how to get it working? Thanks in advance


The basename in getBundle() should be tr.translations, exactly as you have in faces-config.xml.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜