(
转自http://www.blogjava.net/gaofeng/articles/127842.html
作者:Java.net
)
Eclipse3.3刚刚发布,正在学习JSF,于是使用Eclipse3.3做了一个JSF的Demo,很简单,主要是页面的跳转、组件和Bean的绑定等基础...
1、工具准备: Eclipse3.3 WTP2.0 (最好下载一个all-in-one的版本..省的麻烦)...
依赖包:jsf1.2.04-p02,目前的最新版本.内含:jsf-api.jar;jsf-impl.jar.
jstl.jar;standard.jar;commons-beanutils.jar;commons-collections.jar
commons-digester.jar
Web服务器使用Tomcat6..我用的是6.0.10,目前最近的好像是6.0.13.
2、在Eclipse中新建一个Dynamic Web Project...Project name任意..Target Runtime选择Apache Tomcat v6.0,下一步可以设置应用的组件,这里把JSF选上.其余默认..
3、完成后,项目的文件结构已经建好,开始编码:
首先定义一个PersionBean:
1 package com.xzuf.jsf;
2 import java.io.Serializable;
3 /**
4 * PersonBean
5 * @author xzgf
[email protected]
6 * @create 2007-7-2
7 */
8 public class PersonBean implements Serializable {
9 private String name;
10 private String password;
11 /**
12 * @return the password
13 */
14 public String getPassword() {
15 return password;
16 }
17 /**
18 * @param password the password to set
19 */
20 public void setPassword(String password) {
21 this.password = password;
22 }
23 public String getName() {
24 return name;
25 }
26 public void setName(String name) {
27 this.name = name;
28 }
29 }
30 接着在faces-config.xml注册刚定义的PersonBean,使得可以在应用中直接使用bean的实例.
jsf test bean
personBean
com.xzuf.jsf.PersonBean
session
当然,在新版的Eclipse中已经可以图形化的对Bean进行定义了,只要使用默认的打开方式,就可以看到一个非常直观的界面..方便了各种配置...
接着定义两个jsp页面,并增加jsf标签..完整的代码请到附件中下载..
firstjsf.jsp
Please enter your user name and password
style="color: red; font-family: 'New Century Schoolbook', serif; font-style: oblique"
id="errors1" for="userpassword"/>
welcome.jsp
Hello!!
Your password is :
Welcome to JavaServerFace
还是在faces-config.xml.中配置页面导航,可以通过拖拽设置...
全部保存后,右击项目,在Debug中选择Debug on server.....