在Eclipse中開發(fā)JSF

          Posted on 2007-07-04 11:00 Java.net 閱讀(3172) 評論(9)  編輯  收藏 所屬分類: JSF
          Eclipse3.3剛剛發(fā)布,正在學(xué)習(xí)JSF,于是使用Eclipse3.3做了一個JSF的Demo,很簡單,主要是頁面的跳轉(zhuǎn)、組件和Bean的綁定等基礎(chǔ)...
          1、工具準(zhǔn)備: Eclipse3.3  WTP2.0 (最好下載一個all-in-one的版本..省的麻煩)...
                                  依賴包:jsf1.2.04-p02,目前的最新版本.內(nèi)含:jsf-api.jar;jsf-impl.jar.
                                               jstl.jar;standard.jar;commons-beanutils.jar;commons-collections.jar
                                               commons-digester.jar
                                   Web服務(wù)器使用Tomcat6..我用的是6.0.10,目前最近的好像是6.0.13.
           2、在Eclipse中新建一個Dynamic Web Project...Project name任意..Target Runtime選擇Apache Tomcat v6.0,下一步可以設(shè)置應(yīng)用的組件,這里把JSF選上.其余默認(rèn)..
          3、完成后,項目的文件結(jié)構(gòu)已經(jīng)建好,開始編碼:
          首先定義一個PersionBean:
           1 package com.xzuf.jsf;
           2 import java.io.Serializable;
           3 /**
           4  * PersonBean
           5  * @author xzgf <a href='mailto:javac_oracle@163.com'>javac_oracle@163.com</a>
           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,使得可以在應(yīng)用中直接使用bean的實例.
          <managed-bean>
                  
          <description>
                  jsf test bean
          </description>
                  
          <managed-bean-name>
                  personBean
          </managed-bean-name>
                  
          <managed-bean-class>
                  com.xzuf.jsf.PersonBean
          </managed-bean-class>
                  
          <managed-bean-scope>
                  session
          </managed-bean-scope>
              
          </managed-bean>
          當(dāng)然,在新版的Eclipse中已經(jīng)可以圖形化的對Bean進(jìn)行定義了,只要使用默認(rèn)的打開方式,就可以看到一個非常直觀的界面..方便了各種配置...
          接著定義兩個jsp頁面,并增加jsf標(biāo)簽..完整的代碼請到附件中下載..
          firstjsf.jsp
          <body>
          <center>
              
          <h3>Please enter your user name and password</h3>
              
          <f:view>
                  
          <h:form id="myForm">
                      
          <h:panelGrid columns="2">
                          
          <h:outputText value="User Name:"></h:outputText>
                          
          <h:inputText value="#{personBean.name}" required="true"></h:inputText>
                          
          <h:outputText value="Password:"></h:outputText>
                          
          <h:inputSecret id="userpassword" value="#{personBean.password}" required="true"> </h:inputSecret>
                          
          <h:outputText value=""></h:outputText>
                          
          <h:commandButton value="Login" action="login"></h:commandButton>
                          
          <h:graphicImage id="waveImg" url="/images/wave.med.gif"></h:graphicImage>
                          
          <h:message showSummary="true" showDetail="true"
                             style
          ="color: red; font-family: 'New Century Schoolbook', serif; font-style: oblique"
                             id
          ="errors1" for="userpassword"/>
                      
          </h:panelGrid>
                  
          </h:form>
              
          </f:view>
          </center>
          welcome.jsp
          <body>
              
          <f:view>
                  
          <h:outputText value="#{personBean.name}"></h:outputText> Hello!!
                  
          <br>Your password is :
                  
          <h:outputLabel value="#{personBean.password}"></h:outputLabel>
                  
          <h3>Welcome to JavaServerFace</h3>
              
          </f:view>
          </body>
          還是在faces-config.xml.中配置頁面導(dǎo)航,可以通過拖拽設(shè)置...
          全部保存后,右擊項目,在Debug中選擇Debug on server.....

          Feedback

          # re: 在Eclipse中開發(fā)JSF[未登錄]  回復(fù)  更多評論   

          2007-08-15 14:41 by 小小
          有用

          # re: 在Eclipse中開發(fā)JSF[未登錄]  回復(fù)  更多評論   

          2007-08-15 14:42 by 小小
          可不可以再詳細(xì)一下啊

          # re: 在Eclipse中開發(fā)JSF  回復(fù)  更多評論   

          2007-08-15 20:56 by Java.net
          這是我做的一個demo。目前正在試著和Spring結(jié)合起來

          # re: 在Eclipse中開發(fā)JSF  回復(fù)  更多評論   

          2007-08-20 09:26 by kele558
          WTP all-in-one版中(wtp2.0) jsp編輯的時候如何調(diào)出 ui的可視控件?

          很迷惑,,請指點一下。

          # re: 在Eclipse中開發(fā)JSF  回復(fù)  更多評論   

          2007-08-20 12:01 by Java.net
          有個Desgin標(biāo)簽吧.

          # re: 在Eclipse中開發(fā)JSF  回復(fù)  更多評論   

          2007-08-22 11:20 by kele558
          jstl.jar;standard.jar;commons-beanutils.jar;commons-collections.jar
          commons-digester.jar 在那里下載阿?
          jstl.jar;standard.jar需要那個版本的?

          # re: 在Eclipse中開發(fā)JSF  回復(fù)  更多評論   

          2007-08-22 17:07 by Java.net
          好多開源項目里面都帶有的.比如Sping.

          # re: 在Eclipse中開發(fā)JSF  回復(fù)  更多評論   

          2008-05-14 19:34 by dl
          謝謝

          # re: 在Eclipse中開發(fā)JSF  回復(fù)  更多評論   

          2011-06-10 16:48 by 凡躍
          <f:view>標(biāo)簽怎么不能用啊?

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 五峰| 文安县| 九龙坡区| 洪泽县| 仙居县| 滦南县| 肃北| 天全县| 四川省| 任丘市| 文山县| 喀喇沁旗| 宝兴县| 麻阳| 循化| 东丰县| 连城县| 华阴市| 丰镇市| 云和县| 西丰县| 瓦房店市| 建昌县| 陵水| 东乌| 吴旗县| 沁阳市| 社旗县| 含山县| 来安县| 襄汾县| 甘孜| 稻城县| 贵溪市| 化德县| 原阳县| 张家川| 大同县| 萨迦县| 余干县| 宜都市|