Reputation: 1793
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);
Upvotes: 0
Views: 611
Reputation: 1117
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())
.
Upvotes: 0
Reputation: 27880
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.
Upvotes: 1