【发布时间】:2016-07-25 17:48:49
【问题描述】:
我正在使用<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 作为默认值。
我怎样才能做到这一点?
【问题讨论】:
-
你为什么不把它放在集合中的第一个呢?
-
我只是从上面的场景中尝试。
-
如果您在代码中的某处设置
userPref.amount = "FOUR",它应该显示为选定值。
标签: java jsp collections struts struts-tags