FooBar
FooBar

Reputation: 1793

Select Element of Dropdown Box in wicket with dynamically created elements

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

Answers (2)

andypandy
andypandy

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

Xavi L&#243;pez
Xavi L&#243;pez

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

Related Questions