Wicket auto-complete text fields
- I wanted to allow the user to type multiple values. If you compose a message in Gmail, you want to be able to enter multiple recipients, not just one.
- I wanted to have the option to either allow the user to type in options which were not presented (e.g. like when composing a message in Gmail, or typing in tags into Stack Overflow) or restrict them to the options presented (like recipients in Facebook)
- I wanted to either allow the options to be included in the HTML page (e.g. for a set of 10 options, there is no point forcing the user to wait for a server round-trip to fetch matching options), or allow the options to be fetched from the server (e.g. if there are 1M options, they can't be included in the HTML page).
- I wanted the API to be incredibly simple. I want to include a single
<input>into the Wicket HTML document, create the object in Java using a constructor, and attach the data source (client-side or server-side) in a single line.
Surprisingly all of the above are not particularly easy to achieve simultaneously. But they are now done:
MultipleValueAutoSuggestTextField(auto-suggest = can also type in other values)
MultipleValueAutoCompleteTextField(auto-complete = only those values allowed)
And coupled with my newly created extensive multi-lingual location hierarchy database (hierarchy in the sense of 2nd district -> Vienna -> Austria -> Europe -> World, multi-lingual in the sense I have these displayable strings in various languages), allows me to create a MultipleValueLocationTextField subclass, which can be included in a host HTML page in one line of HTML and one line of Java, and which synchronizes its data with a
Location in the client code (e.g. straight from/to a domain object), and it looks like this:
(Alas this code only works with Wicket 1.4 and I never upgraded it to work with current versions.)