以java平臺為基礎,專注項目管理、關注電子商務
          攬住母親的肩頭,敬父親一杯酒,對愛的女人說“我愛你”,和另外一個男人打架,不要打女人,有一個自己的孩子,年輕的時候去漂泊,有自己的一份事業.

          ??????JSF的開發,核心是事件驅動,組件和標簽的封裝程度非常高,很多典型應用已經不需要開發者去處理http。頁面操作會被自動映射到對應的java?bean中,后臺邏輯只需要同java?bean發生交互。整個過程是通過“依賴注入(DI)”來實現的,其設計思想與spring相似。
          ??????下面實例所用的東東包括:Eclipse3.1+MyEclipse4.1,?? tomcat5.0,?? jstl 1.1,? jsf? 。
          SayHello 類
          package org.cssseek.jsf.model.hello;

          public class SayHello {
          ??? public String say(String name)
          ??? {
          ??????? return "你好,"+name;
          ??? }
          }


          HelloDelegater 類
          package org.cssseek.jsf.control.hello;

          import org.cssseek.jsf.model.hello.*;

          public class HelloDelegater {
          ???
          ??? //------屬性---------
          ??? private String name;//表單中的文本框數據會傳到這里
          ??? private String result;//web頁會從這里取得運行結果
          ??? private SayHello sayHello;//model層的對象,并不事例化,由系統注入
          ???
          ??? //-----set/get--------
          ??? public String getName() {
          ??????? return name;
          ??? }
          ??? public void setName(String name) {
          ??????? this.name = name;
          ??? }
          ??? public SayHello getSayHello() {
          ??????? return sayHello;
          ??? }
          ??? public void setSayHello(SayHello sayHello) {
          ??????? this.sayHello = sayHello;
          ??? }
          ??? public String getResult() {
          ??????? return result;
          ??? }
          ??? public void setResult(String result) {
          ??????? this.result = result;
          ??? }
          ???
          ??? //-----邏輯方法---------
          ??? public String say()
          ??? {
          ??????? this.setResult(sayHello.say(this.getName()));
          ??????? return "ok";
          ??? }
          }

          index.jsp頁面

          <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
          <%@ taglib uri="<%@ taglib uri="<%
          String path = request.getContextPath();
          String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
          %>

          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
          <html>
          ? <head>
          ??? <base href="<%=basePath%>">
          ???
          ??? <title>My JSP 'index.jsp' starting page</title>
          ???
          ??? <meta http-equiv="pragma" content="no-cache">
          ??? <meta http-equiv="cache-control" content="no-cache">
          ??? <meta http-equiv="expires" content="0">
          ??? <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
          ??? <meta http-equiv="description" content="This is my page">
          ???
          ??? <!--
          ??? <link rel="stylesheet" type="text/css" href="styles.css">
          ??? -->
          ? </head>
          ?<body>
          ??? <f:view>
          ??????? <h:form>
          ??????????? <h:panelGrid columns="3">
          ??????????????? <h:outputLabel for="name" value="姓名:"/>
          ??????????????? <h:inputText id="name" value="#{HelloDelegater.name}" required="true"/>
          ??????????????? <h:message for="name"/>
          ???????????????
          ??????????????? <h:outputLabel value="#{HelloDelegater.result}"/>
          ??????????? </h:panelGrid>
          ??????????? <h:panelGroup>
          ??????????????? <h:commandButton action="#{HelloDelegater.say}" value="提交"/>
          ??????????? </h:panelGroup>
          ??????? </h:form>
          ??? </f:view>
          ? </body>
          </html>

          faces-config.xml文件

          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN" "

          <faces-config>
          ?<managed-bean>
          ??????? <managed-bean-name>SayHello</managed-bean-name>
          ??????? <managed-bean-class>
          ??????????? org.cssseek.jsf.model.hello.SayHello
          ??????? </managed-bean-class>
          ??????? <managed-bean-scope>request</managed-bean-scope>
          ??? </managed-bean>
          ??? <managed-bean>
          ??????? <managed-bean-name>HelloDelegater</managed-bean-name>
          ??????? <managed-bean-class>
          ??????????? org.cssseek.jsf.control.hello.HelloDelegater
          ??????? </managed-bean-class>
          ??????? <managed-bean-scope>request</managed-bean-scope>
          ??????? <managed-property>
          ??????????? <property-name>sayHello</property-name>
          ??????????? <value>#{SayHello}</value>
          ??????? </managed-property>
          ??? </managed-bean>
          ?
          </faces-config>


          web.xml文件

          <?xml version="1.0" encoding="UTF-8"?>
          <web-app xmlns="
          http://localhost:8080/hellojsfdemo/index.faces

          這個實例就到此結束啦。具體操作這里就沒有詳細寫出來,讀者自己看看吧。




          posted on 2006-03-21 17:50 cssseek 閱讀(1754) 評論(1)  編輯  收藏

          FeedBack:
          # re: jsf實例(Hello)
          2007-02-28 11:23 |
          你的代碼我調試出問題阿,<h:form>這個標簽刪除就可以,加上<h:form>這個標簽就報錯。
          我的msn:xmlin1982@hotmail.com, 我想跟你聯系。  回復  更多評論
            

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


          網站導航:
           

          <2006年3月>
          2627281234
          567891011
          12131415161718
          19202122232425
          2627282930311
          2345678

          常用鏈接

          留言簿(3)

          隨筆分類

          隨筆檔案

          友情鏈接

          最新隨筆

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 商水县| 邢台市| 龙泉市| 汝城县| 西昌市| 天长市| 红安县| 六安市| 灵宝市| 广丰县| 黑龙江省| 林西县| 嘉义市| 仲巴县| 云浮市| 合肥市| 若尔盖县| 陆川县| 高雄县| 岑溪市| 龙胜| 衢州市| 广水市| 镇远县| 大荔县| 吕梁市| 分宜县| 荔浦县| 象州县| 荥经县| 崇阳县| 荆门市| 台安县| 拜泉县| 河曲县| 板桥市| 长岛县| 齐齐哈尔市| 曲阳县| 白玉县| 建瓯市|