01: /*
02: * $Id: AjaxApplication.java 4860 2006-03-12 08:57:48Z ivaynberg $ $Revision:
03: * 4860 $ $Date: 2006-03-12 09:57:48 +0100 (So, 12 Mrz 2006) $
04: *
05: * ==============================================================================
06: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
07: * use this file except in compliance with the License. You may obtain a copy of
08: * the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15: * License for the specific language governing permissions and limitations under
16: * the License.
17: */
18: package wicket.examples.ajax.builtin;
19:
20: import java.util.ArrayList;
21: import java.util.Collections;
22: import java.util.Iterator;
23: import java.util.List;
24: import java.util.Locale;
25:
26: import wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField;
27: import wicket.markup.html.form.Form;
28: import wicket.model.Model;
29: import wicket.util.string.Strings;
30:
31: /**
32: * Page that demos the ajax auto complete text field
33: *
34: * @author ivaynberg
35: */
36: public class AutoCompletePage extends BasePage {
37: /**
38: * Constructor
39: */
40: public AutoCompletePage() {
41: Form form = new Form("form");
42: add(form);
43:
44: form.add(new AutoCompleteTextField("ac", new Model("")) {
45: protected Iterator getChoices(String input) {
46: if (Strings.isEmpty(input)) {
47: return Collections.EMPTY_LIST.iterator();
48: }
49:
50: List choices = new ArrayList(10);
51:
52: Locale[] locales = Locale.getAvailableLocales();
53:
54: for (int i = 0; i < locales.length; i++) {
55: final Locale locale = locales[i];
56: final String country = locale.getDisplayCountry();
57:
58: if (country.toUpperCase().startsWith(
59: input.toUpperCase())) {
60: choices.add(country);
61: if (choices.size() == 10) {
62: break;
63: }
64: }
65: }
66:
67: return choices.iterator();
68: }
69: });
70: }
71: }
|