I'm not sure whether you got martin point . I am going to give some simple solution which will resolve your issue.
let's assume you have SelectionOption
class which you have key
and value
public class SelectOption {
private String key;
private String value;
public SelectOption(String key, String value) {
this.key = key;
this.value = value;
}
// getter and setter
}
Create a simple list of selectOptions and pass to the dropdownchoice
List<SelectOption> selectOptions = new ArrayList<>();
selectOptions.add(new SelectOption("-1","ALL"));
selectOptions.add(new SelectOption("1","Not Started"));
selectOptions.add(new SelectOption("2","In Progress"));
selectOptions.add(new SelectOption("3","Completed"));
//Simply override
choiceRender option to show
key and value
. I have override getDefaultChoice
to remove select one(Its my convenient) since you removed already .
add(new DropDownChoice("selectOption", selectOptions,new ChoiceRenderer<SelectOption>("value","key"){
@Override
public Object getDisplayValue(SelectOption object) {
return object.getValue();
}
@Override
public String getIdValue(SelectOption object, int index) {
return object.getKey();
}
}){
@Override
protected CharSequence getDefaultChoice(String selectedValue) {
return "";
}
});
Output:
<select wicket:id="selectOption" name="selectOption">
<option value="-1">ALL</option>
<option value="1">Not Started</option>
<option value="2">In Progress</option>
<option value="3">Completed</option>
</select>