2011-10-19 49 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,那么它应该就足够了。