all gone

          all gone

          Eclipse下JSF入門

          1.開發環境
             與Eclipse下Struts的開發類似,安裝好Eclipse和Tomcat之后,還需要兩個插件:tomcat 插件和JSF插件(如果相關插件還沒有安裝),以下是相關下載地址:
              Eclipse SDK:
                  http://www.eclipse.org/downloads/index.php 
              JSF:
               https://sourceforge.jp/projects/amateras/files/  
                FaceIDE+htmlEditor,htmlEditer也是必要的
              Tomcat :
                   http://www.sysdeo.com/eclipse/tomcatplugin 
              Plugin Search:
                   http://eclipse-plugins.2y.net/eclipse/search.jsp 
             插件的安裝和配置有問題請直接Google。
          2.開始
              入門嘛,我們就找一個最簡單的Login就可以了

              新建Tomcat project
              加入JSF支持

              新建一個ManagedBean:


          /**
           *
           */
          package com.jsf;




          /**
           * @author lzy
           *
           */
          public class UserBean {
          private String name;
              private String password;
          public String verify() {
               if(this.name.equals("name")&&this.password.equals("password"))
               
                  return "failure";

             else
                  return "success";
          }

           
          /**
          * @return Returns the name.
          */
          public String getName() {
          return name;
          }

          /**
          * @param name The name to set.
          */
          public void setName(String name) {
          this.name = name;
          }


          /**
          * @return Returns the password.
          */
          public String getPassword() {
          return password;
          }

          /**
          * @param password The password to set.
          */
          public void setPassword(String password) {
          this.password = password;
          }


          }

               新建兩個JSP頁面,login.jsp,welcom.jsp

          login.jsp
          <%@ page contentType="text/html; charset=GBK" %>
          <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
          <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

          <html>
          <head>
          <%@ page contentType="text/html; charset=GBK" %>
          <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
          <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

          <html>
          <head>
          <link href="main.css" rel="stylesheet"/>
          <title></title>

          </head>
          <body>
              <f:view>
              <f:loadBundle basename="com.jsf.MessageResources" var="msgs"></f:loadBundle>
             
                  <h:form>
                  <h:panelGrid columns="3" headerClass="header" rowClasses="evenRow,oddRow">
                  <f:facet name="header" >
                  <h:outputText value="#{msgs.header}"/>
                  </f:facet>
                 
                  <h:outputText value="#{msgs.namePromt}"></h:outputText>
                  <h:inputText id="name"  required="true" value="#{user.name}">
                  <f:validateLength minimum="2" maximum="10"></f:validateLength>
                  </h:inputText>
                  <h:message for="name" errorClass="errors"/>
                 
                 
                  <h:outputText value="#{msgs.passwordPromt}"></h:outputText>
                 
                  <h:inputSecret id="password" value="#{user.password}" required="true" redisplay="true">
                  <f:validateLength minimum="2"></f:validateLength>
                  </h:inputSecret>
                  <h:message for="password"/>
                 
                 
                        <f:facet name="footer" >
                  <h:outputText value="#{msgs.footer}"/>
                  </f:facet>
                  </h:panelGrid>          
                      <h:commandButton value="#{msgs.submitPromt}" action="#{user.verify}"/>
                      <h:commandButton value="#{msgs.resetPromt}" type="reset"/>
                  </h:form>
              </f:view>
          </body>
          </html>



          welcome.jsp


          <%@ page contentType="text/html; charset=GBK" %>
          <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
          <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

          <html>
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=GBK"/>
          <title></title>
          </head>
          <body>
              <f:view>
                  <h:outputText value="#{user.name}"/>  is a good boy!
                  <h3>welcome JavaServer Faces</h3>
              </f:view>
          </body>

          </html>
               編輯WEB-INF/lib下的faces-config.xml

          struts-config.xml

          <?xml version="1.0"?>
          <!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN" "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
          <faces-config>
          <navigation-rule>
                  <from-view-id>/login.jsp</from-view-id>
                  <navigation-case>
                      <from-outcome>success</from-outcome>
                      <to-view-id>/welcome.jsp</to-view-id>
                  </navigation-case>
                  <navigation-case>
                      <from-outcome>failure</from-outcome>
                      <to-view-id>/login.jsp</to-view-id>
                  </navigation-case>
          </navigation-rule>


          <managed-bean>
          <managed-bean-name>user</managed-bean-name>
          <managed-bean-class>com.jsf.UserBean</managed-bean-class>
          <managed-bean-scope>session</managed-bean-scope>
          </managed-bean>
          </faces-config>


                 最后是資源文件

          # --login.jsp--
          header=Welcom
          namePromt=Name:
          passwordPromt=Password:
          amountPromt=Amount:
          datePromt=Date:
          submitPromt=Submit
          resetPromt=Reset
          footer=Thank you!


          3.測試
          在test工程中選擇tomcat project->Update context definition
          然后運行Tomcat
          http://127.0.0.1:8080/jsfTest/login.jsf

          posted on 2005-12-10 12:05 all gone 閱讀(17654) 評論(11)  編輯  收藏 所屬分類: Java

          評論

          # re: Eclipse下JSF入門 2007-01-11 10:10 小鳥[匿名]

          login.jsp
          怎么兩個
          <%@ page contentType="text/html; charset=GBK" %>
          <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
          <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>


          MessageResources.prxxxxx 放在哪進里???


          俺試了,,漏洞百出,,,

          不好意思,俺今天才接觸jsf.....  回復  更多評論   

          # re: Eclipse下JSF入門 2007-01-12 18:28 all gone[匿名]

          # --login.jsp-- 是在資源文件里的
          表示這是在login.jsp中用到的

          肯定只會有一個login.jsp  回復  更多評論   

          # re: Eclipse下JSF入門 2007-08-10 08:31 few

          https://sourceforge.jp/projects/amateras/files
          -----------
          樓主給個日文的鏈接,是在賣弄嗎?  回復  更多評論   

          # re: Eclipse下JSF入門 2007-08-31 00:43 hello

          樓上的不懂不要亂說。

          只有日文的。  回復  更多評論   

          # re: Eclipse下JSF入門[未登錄] 2007-09-14 15:39 kevin

          呵呵,笑死了。日文連接。你不還給個中文的,我也沒看懂啊。下來試試的。  回復  更多評論   

          # re: Eclipse下JSF入門[未登錄] 2007-09-14 15:42 kevin

          myeclipse里面都有,有區別嗎?  回復  更多評論   

          # re: Eclipse下JSF入門 2008-04-10 14:32 鵝鵝鵝

          小破程序員還挺愛國,還抗日
          這哥們應該早生70年  回復  更多評論   

          # re: Eclipse下JSF入門 2008-10-29 18:56 sfd

          就沒有自動寫發faces-config.xml文件嘛  回復  更多評論   

          # re: Eclipse下JSF入門 2009-01-13 11:05 飛雪、

          日文的里面點美國國旗應該就都是英文了吧,除了廣告圖片!  回復  更多評論   

          # re: Eclipse下JSF入門[未登錄] 2009-03-17 20:50 躺著讀書

          我也愛日本 咋了

          但是我還是給一個elipse for j2ee的官方版本的jsf環境設置教程。
          http://www.eclipse.org/webtools/jsf/docs/tutorial/JSFTools_1_0_tutorial.html

          eclipse官方是內置了對于jsf的支持的,只是默認這個功能沒有打開。需要配置。新建項目后轉到內置web程序的視圖。比netbeans 好多了。  回復  更多評論   

          # re: Eclipse下JSF入門 2009-07-27 20:51 fuck japan

          fuck japan  回復  更多評論   

          主站蜘蛛池模板: 镇沅| 甘谷县| 长春市| 垦利县| 同心县| 安龙县| 永宁县| 千阳县| 阿克陶县| 凌源市| 于都县| 依安县| 马鞍山市| 秦皇岛市| 东港市| 洛南县| 嘉鱼县| 巴林右旗| 南郑县| 临澧县| 博客| 会同县| 额尔古纳市| 澎湖县| 左贡县| 襄汾县| 屏南县| 泽州县| 沛县| 新化县| 隆回县| 达州市| 民乐县| 曲麻莱县| 海林市| 龙井市| 怀宁县| 庄河市| 苏尼特右旗| 五大连池市| 六安市|