如何从Collection中设置Struts select标记的默认值

时间:2016-04-05 16:39:43

标签: java jsp collections struts struts-tags

我正在使用<html: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'显示为默认值。 我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:3)

默认值在require "awesome_print" include Rails.application.routes.url_helpers AwesomePrint.irb! def y(obj) puts obj.to_yaml end 属性中设置。

  

您是否曾尝试在代码上使用value属性?

value

<强>参考文献:

相关问题