AJAX支持的自动填充表单
|
源代码网整理以下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; 源代码网整理以下 } 源代码网整理以下 this.currentValue = 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 源代码网供稿. |
