2011-10-19 48 views
0

如何自動選擇我創建並添加的下拉框中的元素? 下面的代碼創建下拉框,我想選擇與我的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); 
+0

這是一個很好的建議,@BorisPavlović,你可以在Wicket資源中學習*很多*窺視。總是比javadoc更可靠。 –

+0

感謝您的建議,我現在有一個解決方案,但我會記住下次。我喜歡通過源代碼來更好地瞭解它是如何工作的,只是希望我有更多時間來完成它;) – FooBar

回答

0

如果values對象的exportConfigurationLanguageFormat屬性相匹配的languageFormatArray的一個條目時,頁面呈現這應該自動發生。我建議檢查一下languageFormatArray.contains(values.getExportConfigurationLanguageFormat())

1

作爲@andypandy already pointed outDropDownChoice將檢索/存儲其與values對象的屬性exportConfigurationLanguageFormat相關的值。

確保它已經有一個值,也很重要,確保它的值是DropDownChoice的選擇值之一。實際上,如果它們的equals()返回true,那麼它應該就足夠了。