java Struts <s:select> 标签中的预选值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/479592/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 12:34:31  来源:igfitidea点击:

Preselect value in Struts <s:select> tag?

javaformsstruts2strutsstruts-tags

提问by Dan Burzo

I have this Struts tag:

我有这个 Struts 标签:

<s:select name="country.id" 
          list="countries"  
          listValue="name" 
          listKey="id"
          headerValue="Select Country"
          headerKey=""
          label="Country" />

which outputs the following HTML code:

它输出以下 HTML 代码:

<select name="country.id" tabindex="12" id="registration_country">
    <option value="">Select Country</option>
    <option value="1">United States</option>
    <option value="2">Afghanistan</option>
    <option value="3">Albania</option>
    <option value="4">Algeria</option>
    ...
    <option value="192">Zambia</option>
    <option value="193">Zimbabwe</option>
</select>

How do I specify that I want, for example, "Albania" to be preselected in the list?

例如,如何指定我希望在列表中预选“阿尔巴尼亚”?

回答by Peter Hilton

Use the valueattribute in the s:selecttag:

使用标签中的value属性s:select

<s:select name="country.id" 
list="countries"  
listValue="name" 
listKey="id"
headerValue="Select Country"
headerKey=""
label="Country"
value="3" />

回答by Boris Pavlovi?

Try this:

试试这个:

headerKey="3"