如何自動選擇我創建並添加的下拉框中的元素? 下面的代碼創建下拉框,我想選擇與我的ExportConfiguration對象中的LanguageFormat屬性相對應的項目。使用動態創建的元素在檢票中選擇下拉框元素
編輯:我接受的答案使我轉向了正確的軌道。我不得不在值列表中聲明屬性,導致它自動分配。謝謝!
(Solution)
values.put(
"exportConfigurationLanguageFormat",exportConfiguration.getLanguageFormat());
(/Solution)
//Language Format choices
ArrayList<String> languageFormatArray = new ArrayList<String>();
languageFormatArray.add(firstLanguage);
languageFormatArray.add(firstLanguage + "-" + firstLanguage.toUpperCase());
languageFormatArray.add(firstLanguage + "_" + firstLanguage.toUpperCase());
exportConfigurationLanguageFormat = new DropDownChoice<String>(
"exportConfigurationLanguageFormat", new PropertyModel<String>
(values, "exportConfigurationLanguageFormat"), languageFormatArray);
exportConfigurationLanguageFormat.setRequired(true);
exportConfigurationLanguageFormatFeedback.add(exportConfigurationLanguageFormat);
這是一個很好的建議,@BorisPavlović,你可以在Wicket資源中學習*很多*窺視。總是比javadoc更可靠。 –
感謝您的建議,我現在有一個解決方案,但我會記住下次。我喜歡通過源代碼來更好地瞭解它是如何工作的,只是希望我有更多時間來完成它;) – FooBar