如何从集合中设置Struts select标签的默认值 [英] How to set default value of Struts select tag from the Collection

查看:35
本文介绍了如何从集合中设置Struts select标签的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 标记来读取和显示集合中的值.

I am using <html:select> tag to read and display values from the collection.

<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 文件包含集合值.

The Java file contains the collection values.

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 作为默认值.

I would like to display the value FOUR as a default in the dropdown list.

我怎样才能做到这一点?

How can I achieve this?

推荐答案

默认值在 value 属性中设置.

The default value is set in the value attribute.

您是否尝试过在标签上使用 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>

参考:

这篇关于如何从集合中设置Struts select标签的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆