DropDownChoice で PropertyModel を使用すると問題が発生します。DropdownChoice が変更されるたびに、値を比較して何かを行うものが必要です。これは私がしようとしているものです:
オプションのインスタンス化
private String typeSelected = DEFAULT_TYPE_VALUE;
List<String> typeSelectChoices = new ArrayList<String>();
typeSelectChoices.add(DEFAULT_TYPE_VALUE);
typeSelectChoices.add(TextFactory.TYPE_VALUE_1;
typeSelectChoices.add(TextFactory.TYPE_VALUE_2);
DropDownChoice のインスタンス化
typeSelect = new DropDownChoice<String>(TYPE_SELECT_ID,
new PropertyModel(this, "typeSelected"), typeSelectChoices);
DropDownChoice onChange イベント
typeSelect.add(new AjaxEventBehavior("onchange") {
@Override
protected void onEvent(AjaxRequestTarget target) {
System.out.println(typeSelected);
}
});
選択されたオプションに関係なく、常に「選択」と出力されます。私も試しました:
System.out.println(typeSelect.getModel.getObject());