Posted on 2007-07-02 16:08
Java.net 閱讀(796)
評(píng)論(1) 編輯 收藏 所屬分類:
JSF
看了一上午的JSF,下午做了一個(gè)例子..很簡(jiǎn)單,一共兩個(gè)頁(yè)面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中顯示出來..
開發(fā)環(huán)境為Eclipse3.3版本.安裝了Eclipse用于開發(fā)J2EE的插件WPT2.0...非常好用,不用再去用MyEclipse了...
在Eclipse的Window->Preference->Server->Installed Runtimes中安裝一個(gè)服務(wù)器,本例使用的Tomcat6.0.切換到Eclipse的J2EE視圖,可以看到新建的Server已經(jīng)在右下的server頁(yè)簽看到了...環(huán)境準(zhǔn)備好后,開始建立人員的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;
}
}
打開自動(dòng)生成的faces-config.xml,Eclipse會(huì)用默認(rèn)的圖形界面打開,可以方便的配置Bean管理,頁(yè)面導(dǎo)航等信息...增加一個(gè)作用域?yàn)閟ession的bean管理, 并設(shè)置index.jsp->welcome.jsp的導(dǎo)航...啟動(dòng)服務(wù)器,打開頁(yè)面...完成..