2011-10-19 7 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オブジェクトのプロパティexportConfigurationLanguageFormatlanguageFormatArrayのエントリのいずれかに一致する場合、これは自動的に行われなければなりません。

languageFormatArray.contains(values.getExportConfigurationLanguageFormat())を確認することをお勧めします。

1

@andypandy already pointed outと同様に、DropDownChoiceは、valuesオブジェクトのプロパティexportConfigurationLanguageFormatに対してその値を取得/格納します。

すでに値が設定されていることを確認してください。また、その値がDropDownChoiceの値の1つであることを確認してください。実際には、equals()がtrueを返す場合はidで十分です。

関連する問題