在Eclipse中開發(fā)JSF

          Posted on 2007-07-04 11:00 Java.net 閱讀(3176) 評(píng)論(9)  編輯  收藏 所屬分類: JSF
          Eclipse3.3剛剛發(fā)布,正在學(xué)習(xí)JSF,于是使用Eclipse3.3做了一個(gè)JSF的Demo,很簡(jiǎn)單,主要是頁面的跳轉(zhuǎn)、組件和Bean的綁定等基礎(chǔ)...
          1、工具準(zhǔn)備: Eclipse3.3  WTP2.0 (最好下載一個(gè)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中新建一個(gè)Dynamic Web Project...Project name任意..Target Runtime選擇Apache Tomcat v6.0,下一步可以設(shè)置應(yīng)用的組件,這里把JSF選上.其余默認(rèn)..
          3、完成后,項(xiàng)目的文件結(jié)構(gòu)已經(jīng)建好,開始編碼:
          首先定義一個(gè)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注冊(cè)剛定義的PersonBean,使得可以在應(yīng)用中直接使用bean的實(shí)例.
          <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)可以圖形化的對(duì)Bean進(jìn)行定義了,只要使用默認(rèn)的打開方式,就可以看到一個(gè)非常直觀的界面..方便了各種配置...
          接著定義兩個(gè)jsp頁面,并增加jsf標(biāo)簽..完整的代碼請(qǐng)到附件中下載..
          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è)置...
          全部保存后,右擊項(xiàng)目,在Debug中選擇Debug on server.....

          Feedback

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

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

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

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

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

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

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

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

          很迷惑,,請(qǐng)指點(diǎn)一下。

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

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

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

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

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

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

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

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

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

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

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 康乐县| 崇左市| 千阳县| 广饶县| 蛟河市| 泰来县| 凤台县| 伊金霍洛旗| 和田县| 大田县| 姚安县| 伽师县| 桃园市| 乌拉特后旗| 贡嘎县| 司法| 都安| 综艺| 南城县| 安丘市| 郴州市| 驻马店市| 鸡东县| 额尔古纳市| 台安县| 大化| 南丰县| 塔城市| 会同县| 扎鲁特旗| 汉阴县| 建阳市| 石泉县| 梅河口市| 绥江县| 娄烦县| 梧州市| 奎屯市| 保定市| 讷河市| 新蔡县|