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

          ??????JSF的開發(fā),核心是事件驅(qū)動,組件和標(biāo)簽的封裝程度非常高,很多典型應(yīng)用已經(jīng)不需要開發(fā)者去處理http。頁面操作會被自動映射到對應(yīng)的java?bean中,后臺邏輯只需要同java?bean發(fā)生交互。整個過程是通過“依賴注入(DI)”來實現(xiàn)的,其設(shè)計思想與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;//表單中的文本框數(shù)據(jù)會傳到這里
          ??? private String result;//web頁會從這里取得運行結(jié)果
          ??? private SayHello sayHello;//model層的對象,并不事例化,由系統(tǒng)注入
          ???
          ??? //-----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

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




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

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

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


          網(wǎng)站導(dǎo)航:
           

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

          常用鏈接

          留言簿(3)

          隨筆分類

          隨筆檔案

          友情鏈接

          最新隨筆

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 万山特区| 宣化县| 凯里市| 泉州市| 永德县| 青海省| 普定县| 韶山市| 科技| 巴马| 电白县| 博爱县| 嫩江县| 英吉沙县| 于田县| 蒲江县| 集贤县| 浠水县| 承德市| 郧西县| 东丰县| 微山县| 金塔县| 屏东市| 安泽县| 土默特右旗| 镇原县| 礼泉县| 托克逊县| 长白| 阜康市| 犍为县| 万宁市| 鄱阳县| 百色市| 兰考县| 磐石市| 印江| 当阳市| 阳新县| 保定市|