开发者

spring add default value to form:select

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜