DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> AJAX入門 >> AJAX詳解 >> AJAX支持的自動填充表單
AJAX支持的自動填充表單
編輯:AJAX詳解     

JSf的一個ajax擴展項目, 其實對於使用myfaces的用戶來說還有個更的選擇:使用MyFaces Sandbox 中的 InputSuggestAJax   用法如下:

1.創建一個managed bean:

package test;

import Java.util.ArrayList;

import Java.util.List;

public class Bean {    

            //In that function all what you had to do is to

            //Specify what will be displayed in the list

            //Note that the keyWord is the text entered by the user

            public List getSuggestedWords(String keyWord) {

                        List list = new ArrayList();

                        list.add(keyWord + " Ahmed Saleh");

                        list.add(keyWord + " Kahki");

                        list.add(keyWord + " Kourany");

                        list.add(keyWord + " Kiki");

                        list.add(keyWord + " Saleh Abouetta");

                        list.add(keyWord + " Hashim");

                        return list;

            }

            public String getCurrentValue() {

                        return currentValue;

            }
            public void setCurrentValue(String currentValue) {

                        this.currentValue = currentValue;

            }
            String currentValue;

}

2.     JSP 頁面代碼

<%@ taglib uri="http://Java.sun.com/JSf/Html" prefix="h" %>

<%@ taglib uri="http://Java.sun.com/JSf/core" prefix="f" %>

<%@ taglib uri="http://myfaces.apache.org/sandbox" prefix="s" %>

<Html>

<head>

<title>Ajax JSF sample (InputSuggestAJax)</title>

</head>

<body>

<f:vIEw>

 <h:form>

  <h:outputText value="Enter your name : "/>

   <s:inputSuggestAJax suggestedItemsMethod="#{bean.getSuggestedWords}"

    value="#{bean.currentValue}" />

   <br />

   <h:commandButton action="" value="Submit"/>

   <br />

   <h:outputText value="Your name is #{bean.currentValue}"/>

 </h:form>

</f:vIEw>

</body>    

</Html> 

 3.  web.XML配置

<context-param>

  <param-name>Javax.faces.STATE_SAVING_METHOD</param-name>

  <param-value>clIEnt</param-value>

</context-param>

//Instead of server make the state saving method on the clIEnt to make it works

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved