栏目导航
热点推荐
- 流行的70个AJAX演示及下载
- 20个Ajax关键议题
- AJAX技术在PHP开发中的简单应用
- 如何选择使用AJAX的最佳时机
- 一日精通Ajax技术
- [四天学会ajax] 学习Ajax教程第
- [四天学会ajax] 学习Ajax教程第
- ajax的server部分(php版)
- 在Ajax 应用程序中实现数据之间
- 解决AJAX 跨域访问完整解决方案
- Ajax获取页面被缓存的解决方案
- ajax检测用户名
阅览排行
AJAX支持的自动填充表单
www.jz123.cn 2008-09-21 来源: 中国建站 袁袁整理 我要投递新闻
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}"/>
上一篇:AJAX如何与后台交互 下一篇:Ajax简单示例之改变下拉框动态生成表格