1.Create a text Box
2.Inside the text box drag and drop a autoSuggestBehaviour component
3.In the SuggestedItems create a managed bean for countrySuggester.getCountries
4.Now your Jsf will look like this,
<af:inputText label="Country" value="#{item.country}"
columns="20" id="it5">
<af:autoSuggestBehavior suggestedItems="#{countrySuggester.getCountries}"/>
</af:inputText>
5.In the countrySuggester class make it as this,
import java.util.ArrayList;
import java.util.List;
import javax.faces.model.SelectItem;
public class CountrySuggester {
private List<SelectItem> countries = new ArrayList<SelectItem>();
public CountrySuggester() {
super();
countries.add(new SelectItem("Belgium"));
countries.add(new SelectItem("Hungary"));
countries.add(new SelectItem("Bulgaria"));
countries.add(new SelectItem("India"));
countries.add(new SelectItem("Indonesia"));
countries.add(new SelectItem("United Kingdom"));
countries.add(new SelectItem("United States of America"));
countries.add(new SelectItem("Netherlands"));
countries.add(new SelectItem("Nepal"));
countries.add(new SelectItem("Namibia"));
}
public List<SelectItem> getCountries(String country) {
List<SelectItem> items = new ArrayList<SelectItem>();
for(SelectItem item:countries){
if (item.getLabel().startsWith(country)) {
items.add(item);
}
}
return items;
}
}
No comments:
Post a Comment