简体   繁体   English

Spring Select标签生成隐藏字段

[英]Spring select tag generating hidden field

I am not very familiar with the Spring tag and seems like i am struck in some issue which i am not able to understand as of now. 我对Spring标记不是很熟悉,并且似乎被某些我至今无法理解的问题所震惊。

I have displaying two select tags in my jsp and they are backed by an Arraylist and map here is the code for them 我在我的jsp中显示了两个选择标签,它们由Arraylist支持,这里的映射是它们的代码

<form:select path="prsBTOData[${status.index}].colors" items="${prsBTOData.colors}" 
cssClass="productDetailsSelect"/>

and

<form:select path="prsBTOData[${status.index}].fonts" items="${prsBTOData.fonts}" 
cssClass="productDetailsSelect" >

colors is being backed by Array list while the fonts is being backed by the Map.below is the generated HTML 颜色由数组列表支持,而字体由地图支持。下面是生成的HTML

<select multiple="multiple" class="productDetailsSelect" name="prsBTOData[0].colors" 
    id="prsBTOData0.colors">
     <option selected="selected" value="Red">Red</option>
     <option selected="selected" value="Green">Green</option>
     <option selected="selected" value="Black">Black</option>
</select>
<input type="hidden" value="1" name="_prsBTOData[0].colors">

i am not sure why its doing multiple="multiple" and not showing any drop down but only showing the RED as selected value, while i was expecting a list with drop down options. 我不确定为什么它会执行“ multiple="multiple" ,而不显示任何下拉列表,而只显示RED作为选定值,而我希望包含下拉选项的列表。 even not sure why this hidden field is getting generated and what is its purpose? 甚至不确定为什么会生成此隐藏字段,其目的是什么?

In form:select the items attribute is the list of items that needs to be displayed in select box. form:select items属性中是需要在选择框中显示的项目列表。 And path attribute is the property that is bound with the selected value. path属性是与所选值绑定的属性。

As you have given an arraylist (having multiple values) as the path, spring assumed you wanted a multiple value selected drop down. 当您给定一个arraylist(具有多个值)作为路径时,spring假设您希望下拉选择多个值。

You might want to give like this (assuming you have color property for prsBTOData ) 您可能想要这样(假设您具有prsBTOData color属性)

<form:select path="prsBTOData.color" items="${prsBTOData.colors}"/>

And consider using separate model objects for maintaining static/reference data (colors,fonts) as below: 并考虑使用单独的模型对象来维护静态/参考数据(颜色,字体),如下所示:

<form:select path="prsBTOData.color" items="${referenceData.colors}"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM