...
Code Block | ||
---|---|---|
| ||
public class SelectOption { private String key; private String value; public SelectOption(String key, String value) { this.key = key; this.value = value; }} //...[getters and setters]... } |
Then we create an instance of DropDownChoice
with appropriate ChoiceRenderer
.
Code Block |
---|
SelectOption[] options = new OptionSelectOption[] {new OptionSelectOption("&", "AND"), new OptionSelectOption("|", "OR")}; ChoiceRenderer choiceRenderer = new ChoiceRenderer("value", "key"); add(new DropDownChoice("connective", model, Arrays.asList(options), choiceRenderer); |
The ChoiceRenderer
will use the value of the 'key'
property of SelectOption object in the 'value' attribute in the rendered HTML (e. g. 'key' property value will be used as the option id). The 'value'
property will be used as a display value for the given option. Your backing model must use SelectOption as compared to String in the simple example.
Note |
---|
See also the JavaDoc for the ChoiceRenderer. Another example of custom ChoiceRenderer can be found in the DropDownChoice component reference in the Wicket Library. |
...