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

标签 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作为下拉列表中的默认值。

我怎样才能实现这个目标?

最佳答案

默认值在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/

相关文章:

java - itext:itext 5.4.3如何处理?

java - 在 Tomcat 上运行未反射(reflect)索引页面

java - 从 Tomcat 启动时读取用户输入

java - 如何在 JPanel 对象上调用 getWidth

java - 特定 Java 变量的用途

java - 使 ArrayList 只读

javascript - meteor :虽然尚未加载集合,但已显示模板

arrays - 两个嵌套表集合之间的plsql差异

java - 类型删除和 Flink : what causes run time error?

java - 在 toTomCat 上编译 Java Servlet