使用动态创建的元素选择检票口中下拉框的元素

发布于 2024-12-10 19:57:36 字数 958 浏览 0 评论 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);

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夢归不見 2024-12-17 19:57:36

正如 @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 property exportConfigurationLanguageFormat of the values 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 their equals() returns true.

纸伞微斜 2024-12-17 19:57:36

如果在呈现页面时 values 对象的 exportConfigurationLanguageFormat 属性与 languageFormatArray 中的条目之一匹配,则应自动发生这种情况。

我建议检查 languageFormatArray.contains(values.getExportConfigurationLanguageFormat()) 。

This should occur automatically if the exportConfigurationLanguageFormat property of the values object matches one of the entries in languageFormatArray when the page is rendered.

I would suggest checking that languageFormatArray.contains(values.getExportConfigurationLanguageFormat()).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文