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 selected" isn't displayed in my dropdownlist.
The default value of the select element can be set by using the 'selected' attribute on the required option. This is a boolean attribute. The option that is having the 'selected' attribute will be displayed by default on the dropdown list.
Remember, to get the default values, you do not need to assign values to the variable. static boolean val1; static double val2; static float val3; static int val4; static long val5; static String val6; Now to display the default values, you need to just print the variables.
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="..." />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With