我正在使用<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
作为下拉列表中的默认值。
我怎样才能实现这个目标?
最佳答案
默认值在value
属性中设置。
Have you tried to use the value attribute on the tag?
<html:select property="status" value="...your status choise here..."> <html:optionsCollection name="statusList" label="description" value="id" /> </html:select>
引用文献:
关于java - 如何设置 Struts 从 Collection 中选择标签的默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36432259/