开发者

spring add default value to form:select

开发者 https://www.devze.com 2022-12-29 17:09 出处:网络
I\'m developing a spring application, now I\'ve added a dropdownlist to one of my jsp pages using: <form:select multiple=\"single\" path=\"users[y.count-1].X\" items=\"${Y}\" itemValue=\"id\" item

I'm developing a spring application, now I've added a dropdownlist to one of my jsp pages using:

<form:select multiple="single" path="users[y.count-1].X" items="${Y}" itemValue="id" itemLabel="name"/>

Now I'd like to add the default value "Nothing selected", however I can't seem to find how to do this. I've tried:

<form:select multiple="single" path="users[y.count-1].X" items="${Y}" itemValue="id" itemLabel="name">
   <form:option value="Nothing selected" />
</form:select>

But "Nothing selecte开发者_开发问答d" isn't displayed in my dropdownlist.


You should be able to do

<form:select multiple="single" path="users[y.count-1].X" >
   <form:option value="Nothing selected" />
   <form:options items="${Y}"  itemValue="id" itemLabel="name" />
</form:select>


Just add this line before your options:

<form:option selected="true" value="..." />
0

精彩评论

暂无评论...
验证码 换一张
取 消