- 浏览: 154729 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
lovelimx:
最后一个java文件第37行 orignal = new S ...
JAVA笔试面试必考题系列(六)——字符串(String)杂谈 -
ponlya:
下午又去下了个eclipse3.4,再按这方法,ok了。谢谢楼 ...
eclipse 3.4 下配置 Hibernate tool工具 -
ponlya:
如楼主所说的第1,2步,我在第3步中怎么得不到那个文件夹?换用 ...
eclipse 3.4 下配置 Hibernate tool工具 -
chinaboby2008:
...
JBoss目录结构说明 -
chinaboby2008:
这是java中的j2se部分。是java的基础呢。
有关Java容器的基础知识
国际化的问题有多种实现方法,由于项目需要,最近研究了下,不敢独享。
以下是步骤
1.建立资源bundle文件(以下文件必须建立在src目录下,我放在com.talgroup.international.quotation包下面)
首先建立 UIResources_en_US.txt
Index=Index: UserCode=User Code: UserRole=User Role: Password=Password: UserGroup=User Group: Login=Login Test=?,<>.;:'"{}()#$%&*@ !^/ |
UIResources_zh_CN.txt
Index=序列号: UserCode=用户名: UserRole=用户角色: Password=密码: UserGroup=用户组: Login=登陆 Test=?,<>.;:'"{}()无悔一腔血 有意济苍生#$%&*@ !^/ |
然后建立 转码程序
native2ascii(en-us).bat
native2ascii -encoding TIS-620 UIResources_en_US.txt > UIResources_en_US.properties |
native2ascii(zh-cn).bat
native2ascii -encoding gb2312 UIResources_zh_CN.txt > UIResources_zh_CN.properties |
最后 运行两个批处理程序,产生两个properties文件
2.spring 的application-context.xml文件中配置资源bundle文件
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename">
<value>com.talgroup.international.quotation.UIResources</value>
</property>
</bean>
3.建立后台bean
package com.talgroup.web.quotation.ui;
import java.util.Locale;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.web.util.JavaScriptUtils;
import org.springframework.web.util.HtmlUtils;
public class InternationalBean {
private static String lan="en_US";
private static String jsStr=null;
private static String htmlStr=null;
// ApplicationContext context= new FileSystemXmlApplicationContext("/WEB-INF/resource-config.xml");
private static org.springframework.context.support.ResourceBundleMessageSource context = (org.springframework.context.support.ResourceBundleMessageSource)com.talgroup.app.frmwork.Context.getBean("messageSource");
public String getLan() {
return lan;
}
public void setLan(String lan) {
this.lan = lan;
}
public String zh_CN_Action()
{
this.setLan("zh_CN");
return null;
}
public String zh_HK_Action()
{
this.setLan("zh_HK");
return null;
}
public String en_US_Action()
{
this.setLan("en_US");
return null;
}
public static Locale mapStrToLocale(String lan)
{
if(lan.equals("zh_CN")) return Locale.CHINA;
if(lan.equals("en_US")) return Locale.US;
return Locale.US;
}
public static String JavaScriptEscape(String arg)
{
String str = context.getMessage(arg, null, mapStrToLocale(lan));
jsStr = JavaScriptUtils.javaScriptEscape(str);
return jsStr;
}
public static String HtmlEscape(String arg)
{
String str = context.getMessage(arg, null, mapStrToLocale(lan));
//htmlStr = HtmlUtils.htmlEscape(str);
return str;
}
}
4.jsf的face-config.xml中注册管理bean,session级别
<managed-bean>
<managed-bean-name>internationalBean</managed-bean-name>
<managed-bean-class>
com.talgroup.web.quotation.ui.InternationalBean
</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
5.页面表现层
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:z="http://www.qualcomm.com/jsf/core"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:talui="http://www.talgroup.com/tags"
xmlns:quot="http://www.talgroup.com/quotation/tags"
xmlns:js="http://www.talgroup.com/quotation/tags"
xmlns:html="http://www.talgroup.com/quotation/tags">
<head>
<meta http-equiv="PRAGMA" content="no-cache" />
</head>
<body>
<div id="wrapper" align="center">
<h:form>
<div style="width: 620" align="right">
<h:panelGrid columns="8">
<h:commandLink value="chinese"
style="color:black;font-family:Courier;font-size:10pt;width:120"
action="#{internationalBean.zh_CN_Action}">
</h:commandLink>/
<h:commandLink value="chinese-hk"
style="color:black;font-family:Courier;font-size:10pt;width:120"
action="#{internationalBean.zh_HK_Action}">
</h:commandLink>/
<h:commandLink value="english"
style="color:black;font-family:Courier;font-size:10pt;width:120"
action="#{internationalBean.en_US_Action}">
</h:commandLink>
<h:outputLink id="link1" value="http://www.yourcompany.com">
<h:outputText value="Perferences"
style="color:black;font-family:Courier;font-size:10pt;width:120" />
</h:outputLink>
<h:outputLink id="link2" value="http://www.yourcompany.com">
<h:outputText value="Help"
style="color:black;font-family:Courier;font-size:10pt;width:60" />
</h:outputLink>
<h:outputLink id="link3" value="http://www.yourcompany.com">
<h:outputText value="Contect us"
style="color:black;font-family:Courier;font-size:10pt;width:100" />
</h:outputLink>
</h:panelGrid>
</div>
</h:form>
<h1 id="brandBar">
#{loginBeanWithRoleAndGroup.title}
</h1>
<h:form id="loginForm">
<h:messages layout="table" errorStyle="color: red"></h:messages>
<h:panelGrid columns="5" width="700">
<h:panelGroup>
<h:outputText
style="color:black;font-family:Courier;font-size:10pt;width: 180px"
value="#{html:HtmlEscape('Index')}" />
</h:panelGroup>
<h:panelGroup>
<h:selectOneMenu id="appCode"
value="#{loginBeanWithRoleAndGroup.appCode}" required="true"
style="width: 140px">
<f:selectItems value="#{loginBeanWithRoleAndGroup.applications}" />
<a4j:support event="onchange" reRender="loginForm_userCode"
ajaxSingle="true"
action="#{loginBeanWithRoleAndGroup.lookUpUserByApplication}" />
</h:selectOneMenu>
</h:panelGroup>
<h:panelGroup>
<h:outputText value="" style="width: 50px"></h:outputText>
</h:panelGroup>
<h:panelGroup>
<h:outputText value=""></h:outputText>
</h:panelGroup>
<h:panelGroup>
<h:outputText value=""></h:outputText>
</h:panelGroup>
<h:panelGroup>
<h:outputText
style="color:black;font-family:Courier;font-size:10pt;width: 180px"
value="#{html:HtmlEscape('UserCode')}" />
</h:panelGroup>
<h:panelGroup id="loginForm_userCode">
<h:selectOneMenu id="userCode"
value="#{loginBeanWithRoleAndGroup.userCode}" required="true"
style="width: 140px">
<c:if test="${!empty loginBeanWithRoleAndGroup.users}">
<f:selectItems value="#{loginBeanWithRoleAndGroup.users}" />
</c:if>
<a4j:support event="onchange"
reRender="loginForm_userRole,loginForm_userGroup"
ajaxSingle="true"
action="#{loginBeanWithRoleAndGroup.lookUpUserRoleAndGroup}" />
</h:selectOneMenu>
</h:panelGroup>
<h:panelGroup>
<h:outputText value=""></h:outputText>
</h:panelGroup>
<h:panelGroup style="width: 167px">
<h:outputText
style="color:black;font-family:Courier;font-size:10pt;width: 155px"
value="#{html:HtmlEscape('UserRole')}" />
</h:panelGroup>
<h:panelGroup id="loginForm_userRole">
<h:selectOneMenu value="#{loginBeanWithRoleAndGroup.userRole}"
required="true" style="width: 140px">
<c:if test="${!empty loginBeanWithRoleAndGroup.roles}">
<f:selectItems id="fddd"
value="#{loginBeanWithRoleAndGroup.roles}" />
</c:if>
</h:selectOneMenu>
</h:panelGroup>
<h:panelGroup>
<h:outputText
style="color:Black;font-family:Courier;font-size:10pt;width: 180px"
value="#{html:HtmlEscape('Password')}" />
</h:panelGroup>
<h:panelGroup>
<h:inputSecret id="password"
value="#{loginBeanWithRoleAndGroup.password}" required="true"
requiredMessage="Password can not be empty" style="width: 125px" />
</h:panelGroup>
<h:panelGroup>
<h:outputText value=""></h:outputText>
</h:panelGroup>
<h:panelGroup>
<h:outputText
style="color:black;font-family:Courier;font-size:10pt;width: 155px"
value="#{html:HtmlEscape('UserGroup')}" />
</h:panelGroup>
<h:panelGroup id="loginForm_userGroup">
<h:selectOneMenu value="#{loginBeanWithRoleAndGroup.userGroup}"
required="false" style="width: 140px">
<c:if test="${!empty loginBeanWithRoleAndGroup.groups}">
<f:selectItems id="dsd"
value="#{loginBeanWithRoleAndGroup.groups}" />
</c:if>
</h:selectOneMenu>
</h:panelGroup>
<f:verbatim></f:verbatim>
<h:outputText style="width:170px" value="" />
<h:outputText style="width:170px" value="" />
<h:outputText style="width:170px" value="" />
<h:outputText style="width:170px" value="" />
<h:panelGroup>
<h:inputText style="width:0px;visibility:hidden" id="dsdasdsa"
value="if you remove, you will get error" />
<h:commandButton style="width:130px;" value="#{html:HtmlEscape('Login')}"
action="#{loginBeanWithRoleAndGroup.loginAction}"></h:commandButton>
</h:panelGroup>
<h:panelGroup>
<h:outputText style="width:170px" value="" />
</h:panelGroup>
<h:panelGroup>
<h:outputText style="width:170px" value="" />
</h:panelGroup>
<h:panelGroup>
<h:outputText style="width:170px" value="" />
</h:panelGroup>
</h:panelGrid>
<h:panelGrid columns="1" width="150">
<h:panelGroup style="height: 20px;">
<f:verbatim>
<DIV id="dynamicParameters" style="visibility: hidden;">
</DIV>
</f:verbatim>
</h:panelGroup>
</h:panelGrid>
</h:form>
</div>
<br>
alert test---
<input type="button" value="click" onclick="alert('#{js:JavaScriptEscape('Test')}')"/>
</br>
<br>
html test---
<h:outputText style="width:170px" value="#{html:HtmlEscape('Test')}"/>
</br>
<h:outputText style="width:170px" value="#{html:HtmlEscape('Test')}"/>
</body>
</html>
ps:
xmlns:js="http://www.talgroup.com/quotation/tags" 和xmlns:html="http://www.talgroup.com/quotation/tags">
是我自定义的两个标签,它主要是用来接受页面传过来的键值(例如:Index,UserCode。。。)将它传到后台bean(InternationalBean)中,然后根据这个键值去资源文件中查找相应的message值,最后返回到页面显示,当然这里面涉及到特殊字符转义的问题,这在bean里面都做了处理了。
至于标签如何定义,如何传参数,由于篇幅原因,我将在下一篇文章中做详细的介绍。
发表评论
-
OSI七层模型与 TCP/IP五层模型 TCP/UDP的区别
2010-12-27 18:53 5353OSI七层模型与 TCP/IP五层 ... -
http get post的区别
2010-03-12 11:40 1842定义了与服务器交互的不同方法,最基本的方法是 GET 和 PO ... -
动态增加行 js代码
2010-03-11 16:50 1263<!DOCTYPE HTML PUBLI ... -
全面总结Java泛型
2010-02-23 17:51 852虽然Scala创始人Martin Odersky说当年正是因为 ... -
Java运行时多态性:继承和接口的实现
2010-02-23 17:48 1269Java是面向对象的语言,而运行时多态性是面向对象程序设计代码 ... -
各种集合对比
2010-02-22 17:41 868Collections和Collection的区别 Col ... -
WEB应用中的servlet的 service,doPost,doGet方法的关系
2010-02-22 17:33 1932WEB应用中的servlet的 service,doPost, ... -
Hibernate 缓存机制(二)
2010-02-07 21:47 1043为什么使用hibernate 1、对JDBC操作提供封装, ... -
Hibernate 缓存机制
2010-02-07 21:23 707缓存是介于应用程序和 ... -
J2EE JVM调优 优化
2009-10-19 18:05 909JVM参数调优是一个很头 ... -
eclipse 3.4 下配置 Hibernate tool工具
2009-09-14 17:08 2116http://www.51taobaogood.cn 1. ... -
Valang Validator学习实例入门
2009-09-14 15:48 1361Valang Validator 是较为新颖的插件,在参考胡键 ... -
JavaBean之间拷贝利器-Dozer
2009-09-14 15:42 1857JavaBean之间拷贝利器-Doze ... -
Download and crack Jprobe 8.0
2009-06-15 14:27 3317(转)Download and crack Jprobe 8 ... -
spring获得ApplicationContext
2009-06-08 17:06 20661.servlet Spring获取ApplicationC ... -
操作properties文件总结
2009-06-08 17:00 9661.spring读取 ////////////////// ... -
软件版本GA,RC,Demo,Build意思
2009-05-25 10:48 832转自 http://blog.chinaunix.ne ... -
选择Java接口还是抽象类
2009-05-11 16:43 924很多人有过这样的疑问 ... -
有关Java容器的基础知识
2009-05-08 15:04 1171Java中容器是Java3中比较 ... -
Java性能优化小技巧
2009-05-08 10:35 9151.1.在创建对象时能不用new关健字的最好不要用new创建新 ...
相关推荐
jsf与spring的集成的几种方式,以及jsf的一些技术
JSF国际化范例,源代码 JSF国际化范例,源代码 JSF国际化范例,源代码
spring2.5 与 jsf RI 集成后的猜数字游戏 tomcat6下部署运行
运行在jboss 下的web应用,其中用到 jsf 和spring的整合技术
JSF和Spring集成
一个例子:jsf国际化
部门人员一对多的CRUD操作 hibernate: 管理实体关系映射 spring:数据源配置与获得session IOC依赖注入 和 AOP 事务管理 jsf : backing bean的操作 ... jsf 信息国际化以资源绑定 jsf 表单验证 jsf 导航设定
JSF+SPRING+HIBERNATE
自己收集的jsf+spring整合配置文件及案例
JSF+Spring+Ibatis示例,对学习JAVA企业应用开发有巨大的帮助!
JSF和Spring集成的资料比较少,原理是获得彼此的上下文引用,以此进一步获得各自管理的bean,这是可能的,因为两者是web应用框架都遵循servlet规范,为二者整合提供了可能和基础.
JSF第一步--JSF+Spring+ Hibernate+AJAX编程实践 试读
jsf2+spring sample
一个简单的JSF整合Spring、Hibernate等框架的例子,有助于深入学习的JSF开发!
jsf-spring-4.0.3 jsf他spring结合的工具,from :sorseforce
ajax+jsf+spring+hibernate开发的实例源码
spring+Jsf+hibernate集成实例,并有下拉菜单
这是jsf+spring2.5+jpa(hibernate)的jar包,很多人为了jsj环境而配置半天,在此提供jar包共享。注:除了ajax4jsf和tomahawk-1.1.3.jar,因为csdn只让我上传20mb,大家自己可以下一下自己试试。
此压缩文件包涵了使用JSF+SPRING的所用到的jar包,解压以后直接导入到项目就可以用了!很简单的哦!
JSF+Spring+Hibernate jar文件压缩包,hibernate最小配置,Spring 2.0 jar, richfaces