Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
JSF 1.1 Quick Start
JSF 1.1.01, JDK 1.5, Tomcat 5.5.26 and Eclipse 3.3.2 JEE
Download and install the following:
JDK 1.5
http://java.sun.com/javase/downloads/index_jdk5.jsp
JSF 1.1.01
http://java.sun.com/javaee/javaserverfaces/download.html
Then select
https://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_DeveloperSite/en_US/-/USD/ViewProductDetail-Start?ProductRef=jsf-1_1_01-fcs-oth-JPR@CDSCDS_Developer
Tomcat 5.5.26
http://tomcat.apache.org/download-55.cgi
Eclipse IDE for Java EE Developers
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/releas
e/europa/winter/eclipse-jee-europa-winter-win32.zip
1
Start Eclipse.
Create a new workspace called Faces11Workspace.
2
Create a Dynamic Web Project.
3
Name the Project Faces11Project.
Click the New button to create a new Target Runtime.
4
Select Apache Tomcat v5.5.
Select Also create new local server.
Click Next.
5
Click the Browse button to select the home directory for Tomcat.
6
Navigate to where Tomcat is installed, click OK.
7
Click Finish.
8
Click Next.
9
Select JavaServer Faces the Version to 1.1. This will add the Faces JAR files, create
faces-config.xml and update web.xml.
Select Java 5.0.
Click Next.
10
Click Next.
11
Click New to create a JSF Implementation.
12
Name the Library JSF 1.1.
Click Add.
13
Select the following JAR files from where JSF was installed.
(C:\jsf-1_1_01\lib)
Click Open.
14
You also need to add jstl.jar and standard.jar. These can be found in the Tomcat
directory. Click Add again.
15
Select the following JARs.
(C:\apache-tomcat-5.5.26\webapps\jsp-examples\WEB-INF\lib)
Click Open.
16
Click Finish.
17
Click Finish.
18
Examine web.xml. It has been updated with the <servlet> and <servlet-mapping>
elements.
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>
Faces11Project</display-name>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>
javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
19
Examine 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>
</faces-config>
20
Create a new package called pojos.
21
Create a new folder called resources.
22
Create a new class called User in the pojos package.
Add the java.io.Serializable interface.
Add the default Constructor.
23
Add the following code. The final class should be below:
package pojos;
import java.io.Serializable;
public class User implements Serializable {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public User() {
super();
}
}
24
Create a new file in the resources folder called messages.properties.
25
Add the following:
#Login Page Messages
login_page_title=Login Page
login_text_label=Name:
login_button_label=Login
#Home Page Messages
home_page_title=Home Page
home_header=Welcome
26
Create a new JSP called login.
27
Add the following code.
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<html>
<head>
<title>Login</title>
</head>
<body>
<f:view>
<f:loadBundle basename="resources.messages" var="msg"/>
<h1>
<h:outputText value="#{msg.login_page_title}"/>
</h1>
<h:form id="loginForm">
<h:outputText value="#{msg.login_text_label}"/>
<h:inputText value="#{user.name}" />
<p></p>
<h:commandButton action="login"
value="#{msg.login_button_label}" />
</h:form>
</f:view>
</body>
</html>
28
Create a new JSP called home.
29
Add the following:
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<html>
<head>
<title>Home</title>
</head>
<body>
<f:view>
<f:loadBundle basename="resources.messages" var="msg"/>
<h1><h:outputText value="#{msg.home_page_title}" /></h1>
<h3>
<h:outputText value="#{msg.home_header}" />
<h:outputText value="#{user.name}" />
</h3>
</f:view>
</body>
</html>
30
Update 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>
<navigation-rule>
<from-view-id>/login.jsp</from-view-id>
<navigation-case>
<from-outcome>login</from-outcome>
<to-view-id>/home.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<managed-bean>
<managed-bean-name>user</managed-bean-name>
<managed-bean-class>pojos.User</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
</faces-config>
31
Run login.jsp on the Server.
32
33