posts - 262,  comments - 221,  trackbacks - 0
一、<f:view>、<f:loadbundle>和<html>标记的位置

使用JSF国际化时,如果HTML页面的<title></title>部分需要用到绑定资源文件的信息,则<f:view>和<f:loadbundule>标签必须放在<html>标签之外,诸如以下所示:

没有使用资源绑定之前,页面代码如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>第一个JSF程序</title>
</head>
<body>
  
<f:view>
    
<h:form>
      
<h3>请输入你的名称</h3>
      
<h:outputText value="#{user.errMessage}" /><p>
       名称:
<h:inputText value="#{user.name}" /><p>
       密码:
<h:inputSecret value="#{user.password}" /><p>
      
<h:commandButton value="送出" action="#{user.verify}" />
    
</h:form>
  
</f:view>  
</body>
</html>

使用了资源文件之后,代码的<f:view>,<f:loadbundle>标签提前到<html>标签前面:

<f:view locale="zh_CN">
<f:loadBundle basename="messages" var="msgs"/>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><h:outputText value="#{msgs.titleText}"/></title>
</head>
<body>  
    
<h:form>
      
<h3><h:outputText value="#{msgs.hintText}"/></h3>
      
<h:outputText value="#{user.errMessage}" /><p>      
      
<h:outputText value="#{msgs.nameText}" />
      
<h:inputText value="#{user.name}" /><p>      
      
<h:outputText value="#{msgs.passText}" />
      
<h:inputSecret value="#{user.password}" /><p>      
      
<h:commandButton value="#{msgs.commandText}" action="#{user.verify}" />
    
</h:form>  
</body>
</html>

</f:view>

否则页面在运行时会提示找不到标签,原因就是因为在加载资源文件之前<title></title>就已经使用了绑定,自然无法找到绑定的内容。

二、<f:view>的locale属性和faces-config.xml中<locale-config>配置的优先级别:

1.<f:view>没有设置locale,faces-config.xml没有设置<local-config>时采用浏览器的默认配置

2.<f:view>没有设置locale,但faces-config.xml中设置了<local-config>时,如果支持本地语言则采用<local-config>的<supported-locale>配置,否则采用<default-locale>

3.<f:view>设置了locale时,faces-config.xml没有设置<local-config>时采用<f:view>的配置

4.<f:view>设置了locale时,且faces-config.xml中设置了<local-config>时,采用<f:view>



-------------------------------------------------------------
生活就像打牌,不是要抓一手好牌,而是要尽力打好一手烂牌。
posted on 2008-03-04 22:32 Paul Lin 阅读(1312) 评论(0)  编辑  收藏 所属分类: J2EE 框架

只有注册用户登录后才能发表评论。


网站导航:
 
<2008年3月>
2425262728291
2345678
9101112131415
16171819202122
23242526272829
303112345

常用链接

留言簿(21)

随笔分类

随笔档案

BlogJava热点博客

好友博客

搜索

  •  

最新评论

阅读排行榜

评论排行榜