求助!jsf 国际化问题!
自己找了个视频练了一下JSF,但是碰到问题了。没有错误提示,帮帮忙把!以下是主页面源代码:
<%@ page language="java" pageEncoding="gb2312"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSF 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<f:view locale="#{User.locale}">
<f:loadBundle basename="org.shuye100.resource.message" var="msg"/>
<h:form id="loginForm" rendered="true">
<h:outputText value="#{msg.userName}"></h:outputText><h:inputText id="userName" required="false" rendered="true" value="#{User.userName}"></h:inputText>
<br><h:outputText value="#{msg.password}"></h:outputText><h:inputSecret id="password" required="false" rendered="true" value="#{User.password}"></h:inputSecret>
<br><h:commandButton value="#{msg.login}" action="#{User.verfy}"></h:commandButton>
<br><h:selectOneMenu value="#{User.locale}">//实现中英文切换
<f:selectItem itemValue="en" itemLabel="#{msg.english}"/>
<f:selectItem itemValue="cn" itemLabel="#{msg.chinese}"/>
<f:converter converterId="LocaleConverter"/>
</h:selectOneMenu>
</h:form>
</f:view>
</body>
</html>
以下是faces=config.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN" "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<faces-config >
<managed-bean>
<managed-bean-name>User</managed-bean-name>
<managed-bean-class>org.shuye100.vo.User</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>/index.jsp</from-view-id>
</navigation-rule>
<navigation-rule>
<from-view-id>/welcome.jsp</from-view-id>
</navigation-rule>
<navigation-rule>
<from-view-id>/index.jsp</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/welcome.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>failure</from-outcome>
<to-view-id>/index.jsp</to-view-id>
</navigation-case></navigation-rule>
<converter>
<converter-id>LocaleConverter</converter-id>
<converter-class>
org.shuye100.vo.LocaleConverter
</converter-class>
</converter></faces-config>
我还定义了2个Bean
package org.shuye100.vo;
import java.util.Locale;
public class User {
private String userName;
private String password;
private Locale locale=new Locale("en"); //默认为英文
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String verfy(){ //验证功能,如果页面输入shuye100,则转到success.jsp页面
if(this.userName.equals("shuye100")){
return "success";
}else{
return "failure";
}
}
public Locale getLocale() {
return locale;
}
public void setLocale(Locale locale) {
this.locale = locale;
}
}
和(实现中英文切换功能)
package org.shuye100.vo;
import java.util.Locale;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
public class LocaleConverter implements Converter {
public Object getAsObject(FacesContext arg0, UIComponent arg1, String localeStr)
throws ConverterException {
Locale locale=new Locale("en");
if(localeStr.equals("en")){
return locale;
}else if(localeStr.equals("zh_CN")){
locale=new Locale("zh_CN");
return locale;
}
return locale;
}
public String getAsString(FacesContext arg0, UIComponent arg1, Object locale)
throws ConverterException {
if(locale.toString().equals("en")){
return "en";
}else if(locale.toString().equals("zh_CN")){
return "zh_CN";
}// TODO Auto-generated method stub
return "en";
}
}
实在是运行不成功,这的不知道哪里错了,大侠们帮帮忙吧!