Wicket Remove

wicket.markup.html.form.DropDownChoice

[back to the reference]

A DropDownChoice component is used to let users select an option from a list of available options.

Select your favorite site
Select an integer


Behind the Scenes

Example HTML

<select wicket:id="site">
<option>site 1</option>
<option>site 2</option>
</select>
<select wicket:id="integer">
<option>Fifty</option>
<option>Sixty</option>
</select>

Example Code

/** available sites for selection. */
private static final List SITES = Arrays.asList(new String[] {"The Server Side", "Java Lobby", "Java.Net" });
/** available numbers for selection. */
private static final List INTEGERS = Arrays.asList(new Integer[] { new Integer(1), new Integer(2), new Integer(3) });

public DropDownChoicePage() {
    ...
    // Add a dropdown choice component that uses the model object's 'site' property to designate the
    // current selection, and that uses the SITES list for the available options.
    // Note that when the selection is null, Wicket will lookup a localized string to
    // represent this null with key: "id + '.null'". In this case, this is 'site.null'
    // which can be found in DropDownChoicePage.properties
    form.add(new DropDownChoice("site", SITES));

    // Allthough the default behavior of displaying the string representations of the choices
    // by calling toString on the object might be alright in some cases, you usually want to have
    // more control over it. You achieve this by providing an instance of IChoiceRenderer.
    // Don't forget to check out the default implementation of IChoiceRenderer, ChoiceRenderer.
    form.add(new DropDownChoice("integer", INTEGERS, new IChoiceRenderer() {
         // Gets the display value that is visible to the end user.
        public String getDisplayValue(Object object) {
            ...
        }

         // Gets the value that is invisble to the end user, and that is used as the selection id.
        public String getIdValue(Object object, int index) {
            ...
        }
    }));
}

Further examples & and comments/explanations may be available in the source code.