您的位置:首页 > 移动开发

Websphere Application Server 6.1安装配置(二)

2012-02-11 16:02 525 查看
如果使用JSP作为JSF的视图,那么在每个也没可以用<f:loadBundle>加载国际化文件,但是使用Faclets如何进行国际化文件加载呢?我的做法如下

1. 在faces-config.xml中增加如下配置:

<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
<locale-config>
<default-locale>zh_CN</default-locale>
</locale-config>
<message-bundle>message</message-bundle>

</application>

 2. 在/WEB-INF/classes/下增加message.properties和message_zh_CN.properties两个文件,一个是默认资源文件,一个是中文资源文件。可以根据自己应用的需要添加其他语言支持。

3. 在模版文件,比如/WEB-INF/facelets/template.xhtml中加载这个资源

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">

<f:loadBundle basename="message" var="msg"/>

......

</html>

 4. 在使用这个模版的客户端文件中不必再进行加载,直接使用即可,例如welcome.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
template="/WEB-INF/facelets/template.xhtml">

<ui:define name="title">
${msg.app_title}

</ui:define>
....

</ui:composition>

 因为我使用的是MyFaces JSF 1.1的实现,据说JSF1.2可以完全在faces-config.xml中进行配置,有机会试试~~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: