<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    gembin

    OSGi, Eclipse Equinox, ECF, Virgo, Gemini, Apache Felix, Karaf, Aires, Camel, Eclipse RCP

    HBase, Hadoop, ZooKeeper, Cassandra

    Flex4, AS3, Swiz framework, GraniteDS, BlazeDS etc.

    There is nothing that software can't fix. Unfortunately, there is also nothing that software can't completely fuck up. That gap is called talent.

    About Me

     

    學(xué)習(xí)新Ajax技術(shù)--Dynamic Faces

    引言: 讀此篇文章時(shí),假設(shè)您已經(jīng)具備了JavaServer Faces Technology的基礎(chǔ)知識(shí).
    本文從Dynamic Faces所提供的一個(gè)例子出發(fā).


    Backing Bean
    FruitInfoBean .java
    package simpleDynamicFaces;

    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Map;

    import javax.faces.context.FacesContext;
    import javax.faces.event.ValueChangeEvent;
    import javax.faces.model.SelectItem;


    public class FruitInfoBean {

        
    /** Creates a new instance of FruitInfoBean */
        
    private Map<Object, Object> fruitNamesMap = new HashMap<Object, Object>();
        
    private String fruit = null;
        
    private String variety = null;
        
    private String varietyInfo = null;

        
    public FruitInfoBean() {
            
    this.init();
        }

        
    private void init() {
            FacesContext context 
    = FacesContext.getCurrentInstance();
            System.out.println(
    "Locale:" + context.getViewRoot().getLocale());
            fruit 
    = "Pear";
            variety 
    = "Aurora";
            fruitNamesMap.put(
    "Pear""Aurora,Bartlet,Bosc,Comice,Delicious");
            fruitNamesMap.put(
    "Apple""Adanac,Akane,Ballarat,Braeburn,Fuji,Gala");
            fruitNamesMap.put(
    "Orange""Berna,Hamlin,Moro,Navel,Valencia");
            fruitNamesMap.put(
    "Peach",
                    
    "Brighton,Clingstone,Contender,Eden,Freestone");
        }

        
    /*
         * Handler method called when user selects a variety from the menu. This
         * method updates the variety component model value and sets the varietyInfo
         * model value to the appropriate message.
         
    */
        
    public String updateVariety(ValueChangeEvent e) {
            String newVariety 
    = (String) e.getNewValue();
            String currentFruit 
    = getFruit();
            setVarietyInfo(
    "Information updated:" + newVariety + " Old:"
                    
    + currentFruit);
            
    return null;
        }

        
    public String getFruit() {
            
    return this.fruit;
        }

        
    public void setFruit(String fruit) {
            
    this.fruit = fruit;
        }

        
    protected ArrayList<SelectItem> fruits = null;

        
    public ArrayList<SelectItem> getFruits() {

            fruits 
    = new ArrayList<SelectItem>();
            fruits.add(
    new SelectItem("Pear""Pear"));
            fruits.add(
    new SelectItem("Apple""Apple"));
            fruits.add(
    new SelectItem("Orange""Orange"));
            fruits.add(
    new SelectItem("Peach""Peach"));

            
    return fruits;
        }

        
    public String getVariety() {
            
    return this.variety;
        }

        
    public void setVariety(String variety) {
            
    this.variety = variety;
        }

        
    protected ArrayList<SelectItem> varieties = null;

        
    public ArrayList<SelectItem> getVarieties() {
            varieties 
    = new ArrayList<SelectItem>();
            String[] fruitVarieties 
    = fruitNamesMap.get(this.fruit).toString()
                    .split(
    ",");
            
    for (int i = 0; i < fruitVarieties.length; i++) {
                varieties.add(
    new SelectItem(fruitVarieties[i], fruitVarieties[i]));
            }
            
    return varieties;
        }

        
    /*
         * Handler method for the event of selecting a fruit. This method sets the
         * model value for the variety component and sets the varietyInfo model
         * value to the appropriate message.
         
    */
        
    public void changeFruit(ValueChangeEvent e) {
            String fruitValue 
    = (String) e.getNewValue();
            String[] varieties 
    = fruitNamesMap.get(fruitValue).toString()
                    .split(
    ",");
            setVarietyInfo(
    "Information:" + (varieties[0]));
            setVariety(varieties[
    0]);
        }

        
    public String getVarietyInfo() {
            
    return this.varietyInfo;
        }

        
    public void setVarietyInfo(String varietyInfo) {
            
    this.varietyInfo = varietyInfo;
        }

        
    /*
         * The following code is used with the installDeferredAjaxTransaction use
         * case
         
    */
        
    private String fruitQuiz = null;

        
    public String getFruitQuiz() {
            
    return this.fruitQuiz;
        }

        
    public void setFruitQuiz(String fruit) {
            
    this.fruitQuiz = fruit;
        }

    }

    fireAjaxTx.jsp
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd"
    >
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
    <%@ taglib prefix="jsfExt"  uri="http://java.sun.com/jsf/extensions/dynafaces"%>

    <f:view>
        
    <html>
        
    <head>
        
    <title>Fruit Varieties</title>
        
    <jsfExt:scripts />
        
    </head>
        
    <body bgcolor="white">

        
    <h:form prependId="false" id="form">

            
    <h1>Fruit Varieties</h1>
            
    <h:panelGrid columns="2" cellpadding="4">
                
    <h:outputText value="Select a fruit:" />
                
    <h:outputText value="Select a variety:" />
                
    <h:selectOneRadio id="fruit" value="#{fruitInfoBean.fruit}"
                    onclick
    ="DynaFaces.fireAjaxTransaction(this, { execute: 'fruit'});"
                    valueChangeListener
    ="#{fruitInfoBean.changeFruit}">
                    
    <f:selectItems value="#{fruitInfoBean.fruits}" />
                
    </h:selectOneRadio>

                
    <h:selectOneMenu id="variety" value="#{fruitInfoBean.variety}"
                    onchange
    ="DynaFaces.fireAjaxTransaction(this, { execute: 'variety' });"
                    valueChangeListener
    ="#{fruitInfoBean.updateVariety}">
                    
    <f:selectItems value="#{fruitInfoBean.varieties}" />
                
    </h:selectOneMenu>

            
    </h:panelGrid>
            
    <h:outputText id="varietyInfo" value="#{fruitInfoBean.varietyInfo}" />

        
    </h:form>

        
    </body>
        
    </html>
    </f:view>

    其中的DynaFaces.fireAjaxTransaction方法由jsf-extensions-dynamic-faces.jar里的com_sun_faces_ajax.js定義,這個(gè)方法可以在JSF組件級(jí)別上執(zhí)行AJAX異步更新.

    使用fireAjaxTransaction:
    1.在JSF組件的標(biāo)簽里加JavaScript 事件屬性,如:onClick="DynaFaces.fireAjaxTransaction(paras)"
    2. 在DynaFaces.fireAjaxTransaction加上paras,以便可以傳遞一些參數(shù)到Server.


    execute: 'fruit'的意思是:Id為fruit的JSF組件(包括這個(gè)組件的所有Children),將會(huì)Go Through JSF Life Circle的execute部分. 在這部分生命周期后,當(dāng)前頁(yè)面所有JSF組件將會(huì)通過(guò)Ajaxre-render(這里是默認(rèn)行為,因?yàn)闆](méi)有指定render屬性), 其中execute生命周期部分所做的工作如下:轉(zhuǎn)換和驗(yàn)證數(shù)據(jù),更新數(shù)據(jù)模型和處理Action事件. value-change事件屬于fruit組件,所以當(dāng)發(fā)出AJAX請(qǐng)求時(shí),該事件也會(huì)被處理,從而達(dá)到更新模型數(shù)據(jù)的目的.

    常用的屬性:
    1. execute: A JavaScript String specifying which JSF component id's to process.  

    2. immediate: Not really needed, but if there was validation on the field in "execute" immediate would skip the validation. 

    3. inputs: The values sent to the server.  This may be different than the components processed.  

    4. render: This specifies which area(s) of the screen should be updated with the response.  In this case the 
    <div> around our message text.


    所需的Lib如下:


    有關(guān)Dynamic Faces的包可以從這里下載:https://jsf-extensions.dev.java.net/servlets/ProjectDocumentList

    posted on 2008-03-11 17:32 gembin 閱讀(818) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): JSFAjax

    導(dǎo)航

    統(tǒng)計(jì)

    常用鏈接

    留言簿(6)

    隨筆分類(lèi)(440)

    隨筆檔案(378)

    文章檔案(6)

    新聞檔案(1)

    相冊(cè)

    收藏夾(9)

    Adobe

    Android

    AS3

    Blog-Links

    Build

    Design Pattern

    Eclipse

    Favorite Links

    Flickr

    Game Dev

    HBase

    Identity Management

    IT resources

    JEE

    Language

    OpenID

    OSGi

    SOA

    Version Control

    最新隨筆

    搜索

    積分與排名

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    free counters
    主站蜘蛛池模板: 免费乱理伦在线播放| 免费视频淫片aa毛片| 国产精品亚洲综合一区| 国产精品亚洲lv粉色| 午夜寂寞在线一级观看免费| 亚洲国产精品成人综合色在线婷婷| 无码国产精品一区二区免费3p| 亚洲欧洲日产国码av系列天堂 | 亚洲一区精品伊人久久伊人| 一级看片免费视频囗交| 老司机亚洲精品影视www| a级毛片免费网站| 亚洲爆乳无码专区| 亚洲免费一级视频| 中文字幕亚洲男人的天堂网络| 国产99视频精品免费观看7| 亚洲人成777在线播放| 在线成人a毛片免费播放| 羞羞视频免费网站入口| 伊伊人成亚洲综合人网7777| a色毛片免费视频| 亚洲美女人黄网成人女| 性xxxx视频播放免费| 国产精品亚洲综合一区在线观看| 亚洲精品亚洲人成在线观看下载 | 中文字幕在线亚洲精品| 午夜免费福利小电影| 亚洲喷奶水中文字幕电影| 永久免费无码网站在线观看 | 亚洲午夜精品久久久久久人妖| 91成人免费在线视频| 香蕉视频免费在线| 久久精品国产亚洲av成人| 久久福利资源网站免费看| 国产成人 亚洲欧洲| 亚洲av无码不卡一区二区三区| 台湾一级毛片永久免费| 一级黄色片免费观看| 亚洲国产精品美女| 亚洲人成网站色在线入口| 99re在线这里只有精品免费|