我有一個DropDownChoice問題。我必須預先選擇一個項目,但是我找到的每個教程和示例都只考慮原始類型的列表。檢票口 - DropDownChoice與對象選中
我有一個Object的列表。
class myObject {
private String name;
private String surname;
[setter and getter]
}
在其他類
List<MyObject> myList = some_data_retrieve();
MyObject defaultValue = some_simple_data_retrieve();
使用以下constuctor建立DropDownChoice IM:
final DropDownChoice<T> ddc = new DropDownChoice<T>(id, data, new ChoiceRenderer<T>(choiceRendererExpression, choiceRendererIdExpression));
這樣:
final DropDownChoice<myObject> ddc = new DropDownChoice<myObject>("wicket_id", myList, new ChoiceRenderer<myObject>("name", "surname"));
現在。在每個教程/例子中,他們使用另一個構造函數和一個Model。例如:
private static final List<String> SEARCH_ENGINES = Arrays.asList(new String[] {
"Google", "Bing", "Baidu" });
private String selected = "Google";
DropDownChoice<String> listSites = new DropDownChoice<String>(
"sites", new PropertyModel<String>(this, "selected"), SEARCH_ENGINES);
我已經試過這樣的事情來模擬那種呼叫:
final DropDownChoice<myObject> ddc = new DropDownChoice<myObject>("wicket_id", new PropertyModel<myObject>(this,"defaultValue"),myList, new ChoiceRenderer<myObject>("name", "surname"));
但我得到的是一個錯誤:
No get method defined for class: package$WicketPage expression: defaultValue
請幫我undersand 。
感謝
構造函數中的第二個參數是所選元素的模型。不是默認值的模型。這是,我怎麼理解檢票。 – drdrej 2015-01-21 14:06:29