Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring form:option

Tags:

spring-mvc

Is there any way to mark an option as selected by default, much like the selected attribute in the HTML option tag like <option value="value1" selected>?

like image 490
Eqbal Avatar asked Jun 25 '10 18:06

Eqbal


2 Answers

If the path value of the tag matches the value of options value it will automatically be selected. You don't need anything special

like image 112
Teja Kantamneni Avatar answered Sep 28 '22 01:09

Teja Kantamneni


Is there any way to mark an option as selected by default ???

Just use <spring:option Taglib The first one will be automatically selected

<spring:select name="someProperty">
    <spring:option value="">Select one</spring:option>
    <spring:option value="someValue">Some value<spring:select>
    <!--And so on...-->
<spring:select>

or

<spring:select name="someCollection">
    <spring:option value="">Select one</spring:option>
    <!--Here goes some List added to request-->
    <spring:options itemLabel="propertyNameUsedAsLabel" itemValue="propertyNameUsedAsValue"/>
    <!--And so on...-->
<spring:select>
like image 34
Arthur Ronald Avatar answered Sep 28 '22 03:09

Arthur Ronald