如何本地化JSF 2复合组件 [英] How to localize JSF 2 composite components

查看:207
本文介绍了如何本地化JSF 2复合组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对JSF中复合组件的本地化如何工作有一些疑问,我想了解它是如何工作的。

I have some doubts on how localization works with composite components in JSF, i want to understand well how it works.

所以我决定练习复合组件的本地化用一个小例子。

So i decided to practice localization for composite components with a little example.

按照建议我在复合组件所在的完全相同的文件夹中创建了一个.properties文件(WebContent / resources的子文件夹)

Following the recommendations i created a .properties file in the exactly same folder where the composite component is(A subfolder of WebContent/resources)

labelField1 = FIELD 1
labelField2 = FIELD 2

然后我用#{cc.resourceBundleMap。将本地化文本添加到组件实现:

Then i used #{cc.resourceBundleMap. to add the localized text to the components implmentation:

<html>

<composite:interface>
        ...
</composite:interface>

<composite:implementation>
    <h:form>
            <h:outputText value="#{cc.resourceBundleMap.labelField1}"/>
                                      ...
            <h:outputText value="#{cc.resourceBundleMap.labelField2}"/>
                                              ...
    </h:form>

</composite:implementation> 

</html>

运行应用程序时的问题是:

The problem when i run the application is this:

SEVERE: Error Rendering View[/index.xhtml]
javax.el.ELException: /resources/custom/demoCustomComponent.xhtml @14,63 value="#{cc.resourceBundleMap.labelField1}": java.lang.NullPointerException
....
Caused by: java.lang.NullPointerException
at javax.faces.component.UIComponent.findComponentResourceBundleLocaleMatch(UIComponent.java:1000)

...

我的问题是:

- 我是否需要以某种方式手动加载该消息包或这应该自动发生?

-Do i need to manually load somehow that message bunddle or this should happend automatically?

- 我的应用程序中其他消息包在复合组件所在的文件夹之外,会打扰这个吗?(我还在应用程序的其他地方有一个message_en.properties,用于模板和UI的其他部分)

-Can other message bundles in my app outside the folder where the composite component is, disturb this one?(I also have a message_en.properties somewhere else in the app, for the templates and other parts of the UI)

- 我该如何解决?

-How can i fix it?

推荐答案

res的文件名源包必须完全与组件的文件名相同。

The filename of the resource bundle has to be exactly the same as the component's filename.

所以,如果你有一个 demoCustomComponent.xhtml 表示复合组件的文件,然后你应该有一个 demoCustomComponent.properties 文件,其中包含(默认)本地化消息。您可以使用例如 demoCustomComponent_es.properties 对其进行国际化,但是路径中应该始终有一个默认值。

So, if you have a demoCustomComponent.xhtml file representing the composite component, then you should have a demoCustomComponent.properties file holding the (default) localized messages. You can internationalize it with for example demoCustomComponent_es.properties, but you should always have a default one in the path.

这篇关于如何本地化JSF 2复合组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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