Oops! JSF Quick Start!
Purpose:
学习使用一个JSF
Precondition:
/Files/pixysoft/jsf_simple_lib.part1.rar
/Files/pixysoft/jsf_simple_lib.part2.rar
Reference:
http://www.exadel.com/tutorial/jsf/jsftutorial-kickstart.html#compile
Tutorial:
新建一个项目Dynamic Web Project,名字Oops_JSF
在lib目录下添加以下jar文件
修改web.xml
<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<!-- Faces Servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup> 1 </load-on-startup>
</servlet>
<!-- Faces Servlet Mapping -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
</web-app>
在WEB-INF目录下面添加文件faces-config.xml
<?xml version="1.0"?>
<!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>
<navigation-rule>
<from-view-id>/pages/inputname.jsp</from-view-id>
<navigation-case>
<from-outcome>greeting</from-outcome>
<to-view-id>/pages/greeting.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<managed-bean>
<managed-bean-name>personBean</managed-bean-name>
<managed-bean-class>jsfks.PersonBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
</faces-config>
在WebContent下面添加pages目录,然后新建2个文件
greeting.jsp
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<f:loadBundle basename="jsfks.bundle.messages" var="msg"/>
<html>
<head>
<title>greeting page</title>
</head>
<body>
<f:view>
<h3>
<h:outputText value="#{msg.greeting_text}"/>,
<h:outputText value="#{personBean.personName}"/>
<h:outputText value="#{msg.sign}"/>
</h3>
</f:view>
</body>
</html>
inputname.jsp
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<f:loadBundle basename="jsfks.bundle.messages" var="msg"/>
<html>
<head>
<title>enter your name page</title>
</head>
<body>
<f:view>
<h1>
<h:outputText value="#{msg.inputname_header}"/>
</h1>
<h:form id="helloForm">
<h:outputText value="#{msg.prompt}"/>
<h:inputText value="#{personBean.personName}"/>
<h:commandButton action="greeting" value="#{msg.button_text}"/>
</h:form>
</f:view>
</body>
</html>
在WebContent目录下面添加一个index.jsp文件
<html>
<body>
<jsp:forward page="/pages/inputname.jsf" />
</body>
</html>
在src目录下面添加jsfks目录,再添加PersonBean.java文件
package jsfks;
publicclass PersonBean {
String personName;
/**
*@returnPersonName
*/
public String getPersonName() {
returnpersonName;
}
/**
*@paramPersonName
*/
publicvoid setPersonName(String name) {
personName = name;
}
}
在jsfks目录下添加bundle目录,再添加文件messages.properties
inputname_header=JSFKickStart
prompt=Tellusyourname:
greeting_text=WelcometoJSF
button_text=SayHello
sign=!
最后整个文件夹为:
最后Run as … On Server
注意:一定要把之前的server配置删除,run as 的时候是一个新的server,就因为这个原因我忙了几个小时,才发现出错是因为之前存在了另外一个roject在server上,也不提示。
posted on 2007-09-04 18:39
张辰 阅读(355)
评论(0) 编辑 收藏 所属分类:
Dr. Oops