使用动态创建的元素选择检票口中下拉框的元素
如何在下拉框中自动选择我正在创建和添加的元素? 下面的代码创建下拉框,我想选择与 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);
How can I automatically select an element in my dropdown box that I'm creating and adding?
The code below creates the dropdown box, I would like to select the item that corresponds to the LanguageFormat property in my ExportConfiguration object.
Edit: The answer I've accepted turned me on to the right track. I had to declare the property in the values list which caused it to automatically be assigned. Thanks!
(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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 @andypandy 已经指出的,
DropDownChoice
将检索/存储与该属性相关的值values
对象的exportConfigurationLanguageFormat
。确保它已经有一个值,同样重要的是,确保它的值是
DropDownChoice
选项中的值之一。实际上,如果它们的equals()
返回 true,那么 id 就足够了。As @andypandy already pointed out, the
DropDownChoice
will be retrieveing/storing its value in relation to the propertyexportConfigurationLanguageFormat
of thevalues
object.Make sure it already has a value, and also important, make sure that its value is one of the values in the
DropDownChoice
's choices. Actually id should be sufficient if theirequals()
returns true.如果在呈现页面时
values
对象的exportConfigurationLanguageFormat
属性与languageFormatArray
中的条目之一匹配,则应自动发生这种情况。我建议检查 languageFormatArray.contains(values.getExportConfigurationLanguageFormat()) 。
This should occur automatically if the
exportConfigurationLanguageFormat
property of thevalues
object matches one of the entries inlanguageFormatArray
when the page is rendered.I would suggest checking that
languageFormatArray.contains(values.getExportConfigurationLanguageFormat())
.