JSF初学第一个例子

Posted on 2007-07-02 16:08 Java.net 阅读(782) 评论(1)  编辑  收藏 所属分类: JSF
看了一上午的JSF,下午做了一个例子..很简单,一共两个页面index.jsp和welcome.jsp

index.jsp主要源码
<f:view>
        
<h:form>
            
<h3>In put your name:</h3>
            Name:
<h:inputText value="#{personBean.name}"></h:inputText>
            
<h:commandButton value="Login" action="login"></h:commandButton>
        
</h:form>
    
</f:view>
welcome.jsp主要源码
<f:view>
        
<h:outputText value="#{personBean.name}"></h:outputText> Hello!!
        
<h3>Welcome to JavaServerFace</h3>
    
</f:view>
在index.jsp中录入姓名,然后在welcome中显示出来..
开发环境为Eclipse3.3版本.安装了Eclipse用于开发J2EE的插件WPT2.0...非常好用,不用再去用MyEclipse了...
在Eclipse的Window->Preference->Server->Installed Runtimes中安装一个服务器,本例使用的Tomcat6.0.切换到Eclipse的J2EE视图,可以看到新建的Server已经在右下的server页签看到了...环境准备好后,开始建立人员的Bean
PersonBean代码:
package com.xzuf.jsf;

import java.io.Serializable;
/**
 * PersonBean
 * 
@author xzgf <a href='mailto:javac_oracle@163.com'>javac_oracle@163.com</a>
 * @create 2007-7-2
 *
 
*/
public class PersonBean implements Serializable {
    
private String name;
    
public String getName() {
        
return name;
    }
    
public void setName(String name) {
        
this.name = name;
    }
}
打开自动生成的faces-config.xml,Eclipse会用默认的图形界面打开,可以方便的配置Bean管理,页面导航等信息...增加一个作用域为session的bean管理, 并设置index.jsp->welcome.jsp的导航...启动服务器,打开页面...完成..

Feedback

# re: JSF初学第一个例子  回复  更多评论   

2007-09-28 17:45 by 千里冰封
呵呵,简单不要紧,慢慢就好了

只有注册用户登录后才能发表评论。


网站导航: