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


AddThis Social Bookmark Button

相关文档(Relevant Entries)
Ajax按需读取数据生成下级菜单[转]
Ajax在PHP开发中的应用[转]
利用PHP和AJAX创建RSS聚合器
Ajax文档
AJAX掀起桌面网络开发的新篇章
Ajax专题
DWR version 2.0 milestone 1 is released
Better File Uploads with AJAX and JavaServer Faces
WoW Powerleveling
Posted on April 1, 2007 10:33 PM | | | Comments (0) | | TrackBacks (0)

引用地址(TRACKBACKS)
 
TrackBack URL for this entry:
http://www.wujianrong.com/mt-tb.cgi/5005

发布评论(ADD YOUR COMMENTS)
 
感谢您参与评论;发表您的意见时请保持文章的相关性;不相关的或是单纯宣传的内容可能会被删掉。您的E-mail只是用来确认您发表的文章,不会出现在网页上。
Please keep your comments relevant to this blog entry. Email addresses are never displayed, but they are required to confirm your comments.

称呼(Name):      记住我的个人信息(Remember)
邮箱(Email):
网址(URL):
评论(Add your comments):

相关内容
广告计划