您的位置:首页 > Web前端 > JavaScript

jsf学习二(国际化)

2006-08-20 10:33 274 查看
国际化(I18N)就是设计软件应用,在不改变它们程序逻辑的前提下支持各种语言和区域
本地化(L10N)就是设计软件应用支持特定地区
由于数据经过本地化,因此同一应用程序能在全世界使用
当增加一种新的语言时,应用不需要重新编译
在显示和文化相关的数据(例如日期或货币)时,格式应用遵循用户的语言和区域
文本内容(如状态消息和组件标签)不是硬编码到应用程序中,而通常是从文本文件中动态提取的

国际化的步骤

创建一个包含应用程序默认语言的键/值对的文件
文件命名格式:
Filename_languagecode_CountryCode.properties
例如:
ApplicationResources_zh_CN.properties

JSF 提供 <f:loadBundle> 标签以加载资源包
此标签具有两个属性:basename 和 var
basename 指定要加载的 properties 文件的名称
var属性用来为该properties文件起一个别名




<f:view>


<f:loadBundle basename="csdnblog" vars="csdn" />


….


<h:outputLabel value="#{csdn.first}" />


</f:view>

资源文件编译

native2ascii –encoding gb2312 messagesCN.properties messages_zh_CN.properties



一个登陆实现国际化

后台检查登陆是否正确




public String Login(string userName,string passWord) ...{




if ( UserName=="blog") ...{


return "success";




} else ...{


FacesContext context = FacesContext.getCurrentInstance();


ResourceBundle bundle = ResourceBundle.getBundle("messages", context.getViewRoot().getLocale());


String msg = "";


if ( username=="" || passWord=="")


msg = bundle.getString("username_isnull");




context.addMessage (null, new FacesMessage(msg));


return "shibai";




}


}

前台


<f:loadBundle basename="csdnblog" var="csdn"/>


<html>


<f:view>


<h:form>


<h:outputText value="#{csdn.login}"/> <br/>


<h:messages style="color: blue"/><br/>


<h:inputText id="username" value="#{UserBean.userName}"


required="true">


<f:validateLongRange minimum="0" maximum="20"/>


</h:inputText><br/><br/>






<h:outputText value="#{csdn.password}"/> <br/>


<h:messages style="color: blue"/><br/>


<h:inputText id="pssword" value="#{UserBean.passWord}"


required="true">


<f:validateLongRange minimum="0" maximum="16"/>


</h:inputText><br/><br/>






<h:commandButton value="#{csdn.button_title}"


action="#{userBean.Login}"/>


</h:form>


</f:view>


</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: