gpt4 book ai didi

java - 如何设置Struts的默认值从集合中选择标签

转载 作者:行者123 更新时间:2023-11-29 04:47:58 24 4
gpt4 key购买 nike

我正在使用 <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的默认值从集合中选择标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36432259/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com