I'm using richfaces to get autocomplete but it doesn't work. I studied the richfaces showcases and QA's here but I can't get it to work. I get no error message on the console, the Horse list is not empty, richfaces with AutocompleteBase.js are loaded,
My xhtml:
...
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
...
<h:form>
<rich:autocomplete mode="cachedAjax" minChars="1"
autocomopleteMethod="#{autoCompleteBean.autocomplete}"/>
</h:form>
...
My autocomplete Bean:
@Named
@RequestScoped
public class AutoCompleteBean {
private List<String> autocompleteList;
private List<Horse> horses;
@PostConstruct
private void init() {
autocompleteList = new ArrayList<String>();
for (Hors horse : horses) {
autocompleteList.add(horse.getName());
}
}
public List<String> autocomplete(String prefix) {
ArrayList<String> result = new ArrayList<>();
for (Iterator<Horse> it = autocompleteList.iterator(); it.hasNext();) {
if (it.next().getName().startsWith(prefix)) {
result.add(it.next());
}
}
return result;
}
}