2016-04-05 16 views
1

<html:select>タグを使用して、コレクションの値を読み取り、表示しています。CollectionからStruts selectタグのデフォルト値を設定する方法

<tr> 
    <td><bean:message key="prompt.my.amount" /></td> 
    <td> 
     <html:select property="userPref.amount" style="width:170px"> 
      <html:options collection="myAmts" property="value" labelProperty="label" /> 
     </html:select> 
    </td> 
</tr> 

Javaファイルには、コレクション値が含まれています。

public Collection getMyAmts() { 
    if (Utils.empty(myAmts)) { 
     myAmts = new Vector(); 
     myAmts.add(new LabelValueBean("ONE", "one")); 
     myAmts.add(new LabelValueBean("TWO", "two")); 
     myAmts.add(new LabelValueBean("Three", "three")); 
     myAmts.add(new LabelValueBean("FOUR", "four")); 
    } 
    return myAmts; 
} 

私は、ドロップダウンリストのデフォルトとして値'FOUR'を表示したいと思います。 これをどうすれば実現できますか?

+0

? – robotlos

+0

私は上記のシナリオから試しています。 – Mdhar9e

+0

あなたのコードのどこかに 'userPref.amount =" FOUR "を設定した場合、それは選択された値として表示されるはずです。 – Evgeny

答えて

3

デフォルト値はvalue属性に設定されています。

あなたがタグにvalue属性を使用しようとしたことがありますか?

<html:select property="status" value="...your status choise here..."> <html:optionsCollection name="statusList" 
label="description" value="id" /> </html:select> 

参考文献:あなたはそれコレクションの最初の1つとなっていないのはなぜ

関連する問題