《Core JavaServer Faces 3rd Edition》中第四章的代码:
LocaleChanger.java
package com.corejsf;
import java.io.Serializable;
import java.util.Locale;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
@ManagedBean
@SessionScoped
public class LocaleChanger implements Serializable {
public String germanAction() {
FacesContext context = FacesContext.getCurrentInstance();
context.getViewRoot().setLocale(Locale.GERMAN);
return null;
}
public String englishAction() {
FacesContext context = FacesContext.getCurrentInstance();
context.getViewRoot().setLocale(Locale.ENGLISH);
return null;
}
public String chineseAction() {
FacesContext context = FacesContext.getCurrentInstance();
context.getViewRoot().setLocale(Locale.CHINESE);
return null;
}
}
UserBean.java
package com.corejsf;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean(name="user")
@SessionScoped
public class UserBean implements Serializable {
private String name;
private String password;
private String aboutYourself;
public String getName() { return name; }
public void setName(String newValue) { name = newValue; }
public String getPassword() { return password; }
public void setPassword(String newValue) { password = newValue; }
public String getAboutYourself() { return aboutYourself; }
public void setAboutYourself(String newValue) { aboutYourself = newValue; }
}
index.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>#{msgs.indexWindowTitle}</title>
</h:head>
<h:body>
<h:form>
<h:commandLink action="#{localeChanger.germanAction}">
<h:graphicImage library="images" name="de_flag.gif"
style="border: 0px; margin-right: 1em;" />
</h:commandLink>
<h:commandLink action="#{localeChanger.englishAction}">
<h:graphicImage library="images" name="en_flag.gif"
style="border: 0px; margin-right: 1em;" />
</h:commandLink>
<h:commandLink action="#{localeChanger.chineseAction}">
<h:graphicImage library="images" name="cn_flag.gif"
style="border: 0px; margin-right: 1em;" />
</h:commandLink>
<p>
<h:outputText value="#{msgs.indexPageTitle}"
style="font-style: italic; font-size: 1.3em" />
</p>
<h:panelGrid columns="2">
#{msgs.namePrompt}
<h:inputText value="#{user.name}" />
#{msgs.passwordPrompt}
<h:inputSecret value="#{user.password}" />
#{msgs.tellUsPrompt}
<h:inputTextarea value="#{user.aboutYourself}" rows="5"
cols="35" />
</h:panelGrid>
<h:commandButton value="#{msgs.submitPrompt}" action="success" />
</h:form>
</h:body>
</html>
thankYou.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!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:h="http://java.sun.com/jsf/html">
<h:head>
<title>#{msgs.thankYouWindowTitle}</title>
</h:head>
<h:body>
<h:outputText value="#{msgs.namePrompt}" style="font-style: italic"/>
#{user.name}
<br/>
<h:outputText value="#{msgs.aboutYourselfPrompt}" style="font-style: italic"/>
<br/>
<pre>#{user.aboutYourself}</pre>
</h:body>
</html>
faces-config.xml
<?xml version="1.0"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<navigation-rule>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/thankYou.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<application>
<locale-config>
<default-locale>en</default-locale>
<supported-locale>zh</supported-locale>
<supported-locale>de</supported-locale>
</locale-config>
<resource-bundle>
<base-name>com.corejsf.messages</base-name>
<var>msgs</var>
</resource-bundle>
</application>
</faces-config>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
</web-app>
运行图片:
- 大小: 8.4 KB
分享到:
相关推荐
Core Java Server Faces 3Rd Edition.Pdf 缺分,本书涵盖JSF2.0
Core JavaServer Faces 3rd Edition 核心JSF第三版(英文)
Core JavaServer Faces 3rd Edition JSF核心编程(第三版) JSF2 PDF高清原版
To help you quickly tap into the power of JSF 2.0, the third edition of Core JavaServer™ Faces has been completely updated to make optimum use of all the new features. The book includes Three ...
JSF(Java Server Faces)技术为开发基于网络用户界面的Java开发者提供了标准的编程接口API以及标签库。就像Struts框架一样,JSF定义了一套JSF标签 JSF的全称 1、Joint Strike Fighter (JSF) 2、Java Server ...
Core JavaServer Faces, Second Edition
To help you quickly tap into the power of JSF 2.0, the third edition of Core JavaServer™ Faces has been completely updated to make optimum use of all the new features. The book includes Three totally...
Core JavaServer Faces 源代码,code,jsf 例子程序
jsf1.2 javaserver faces
JavaServer Faces (JSF, or simply “Faces”) makes it easy to develop web applications by bringing support for rich, powerful user interface components (such as text boxes, list boxes, tabbed panes, ...
Core JavaServer Faces, 2nd Edition <br>JSF核心编程第二版
JSF核心编程 第二版PDF 经典丛书,包含源代码
Core JavaServer Faces, 2nd Edition <br>JSF核心编程第二版
《JavaServer Faces核心编程(第3版)》源代码。JSF架构学习之必备,Oracle ADF研究之辅助。
core JAVASERVER™ FACES THIRD EDITION
Manning - JavaServer Faces JSF in Action.pdf
附件中是本人做好的例子和JSF需要的jar包 博文链接:https://di201yao.iteye.com/blog/165029
JavaServer Faces (JSF) 是一种用于构建Java Web 应用程序的标准框架(是Java Community Process 规定的JSR-127标准)。它提供了一种以组件为中心的用户界面(UI)构建方法,从而简化了Java服务器端应用程序的开发。...