java spring web mvc中的组合框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1673227/
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 17:32:50  来源:igfitidea点击:

combo box in spring web mvc

javajakarta-eespring-mvc

提问by Nirmal

I am using spring web mvc for my app's UI part..

我正在为我的应用程序的 UI 部分使用 spring web mvc。

By using following code, i am getting List Box where i can select more then 1 value..

通过使用以下代码,我得到了列表框,我可以在其中选择多于 1 个值。

<form:select path="domainsList">
<form:options items="${domainsList}" itemValue="domain" itemLabel="domain"/>
</form:select>

But I need a drop down combo box...

但我需要一个下拉组合框...

Can any one suggest how can i convert it to combo box ?

任何人都可以建议我如何将其转换为组合框?

Thanks in advance..

提前致谢..

采纳答案by Nirmal

Sorry, for asking silly question.. But i got working combo box by following code :

对不起,问愚蠢的问题..但我通过以下代码得到了工作组合框:

<form:select path="domainsList" multiple="false" size="1">
<form:options items="${domainsList}" itemValue="domain" itemLabel="domain"/>
</form:select>
</form:form>

回答by Triqui

Spring will decide the type of field to use depending on the type of data, so if the 'path' field is an object, it will show a dropdown, but if it is a "list" (array, collection, ...) it will show a list, unless you specify multiple="false"

Spring 将根据数据类型决定要使用的字段类型,因此如果 'path' 字段是一个对象,它将显示一个下拉列表,但如果它是一个“列表”(数组,集合,...)它将显示一个列表,除非您指定 multiple="false"

This will show a list with multiple selection:

这将显示一个多选列表:

Integer[] ids;
<form:select path="ids" items="${whatever}" />

This will show a dropdown with single selection:

这将显示一个带有单项选择的下拉列表:

Integer id;
<form:select path="id" items="${whatever}" />

This will also show a dropdown with single selection:

这还将显示一个带有单项选择的下拉列表:

Integer[] ids;
<form:select path="ids" items="${whatever}" multiple="false" />

回答by squiddle

The spring "form:select" tag just wraps the HTML select element. It also has an attribute sizewhich has to be set to a value of 1to let this selection become rendered as a combobox (in most browsers).

spring "form:select" 标签只是包装了 HTML select 元素。它还有一个属性size必须将其设置为值1才能让此选择呈现为组合框(在大多数浏览器中)。

this is basic HTML: http://www.w3.org/TR/html4/interact/forms.html#adef-size-SELECT

这是基本的 HTML:http: //www.w3.org/TR/html4/interact/forms.html#adef-size-SELECT

<form:select path="domainsList" size="1">
   <form:options items="${domainsList}" itemValue="domain" itemLabel="domain"/>
</form:select>

@Nirmal please check your markup. This should work.

@Nirmal 请检查您的标记。这应该有效。

<html>
    <SELECT name="selection" size="1">
        <OPTION selected label="none" value="none">None</OPTION>
        <OPTION label="1" value="1">OPTION 1</OPTION>
        <OPTION label="2" value="2">OPTION 2</OPTION>
        <OPTION label="3" value="3">OPTION 3</OPTION>
    </SELECT>
</html>