jsf, 一个ajax扩展项目, 其实对于使用myfaces的用户来说还有个更的选择:使用MyFaces Sandbox 中的 InputSuggestAjax 用法如Exemplo:
1.创建一个bean gerenciado:
teste de pacote;
importar java.util.ArrayList;
importar java.util.List;
public class Bean {
//Nessa função tudo o que você tinha que fazer era
//Especificar o que será exibido na lista
//Observe que a palavra-chave é o texto digitado pelo usuário
public List getSuggestedWords(String keywords) {
List list = newArrayList();
list.add(palavra-chave + "Ahmed Saleh");
list.add(palavra-chave + "Kahki");
list.add(palavra-chave + " Kourany");
list.add(palavra-chave + "Kiki");
list.add(palavra-chave + " Saleh Abouetta");
list.add(palavra-chave + "Hashim");
lista de retorno;
}
public String getCurrentValue() {
return currentValue;
}
public void setCurrentValue(String currentValue) {
this.currentValue = currentValue;
}
String valorAtual;
}
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>Amostra Ajax JSF (InputSuggestAjax)</title>
</head>
<body>
<f:view>
<h:form>
<h:outputText value="Digite seu nome: "/>
<s:inputSuggestAjax SuggestedItemsMethod="#{bean.getSuggestedWords }"
value="#{bean.currentValue}" />
<br />
<h:commandButton action="" value="Submit"/>
<br />
<h:outputText value="Seu nome é #{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>
//Em vez de servidor, faça o método de salvamento de estado no cliente para fazê-lo funcionar