tags:

views:

66

answers:

2
+1  Q: 

Spring form:option

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>?

A: 

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

Teja Kantamneni
I understand that, but some business logic needs me to have a default selected item the first time it loads (subsequent loads, select list goes away and is replaced by a hidden field).
Eqbal
Set that as the default value for that field in command object.
Teja Kantamneni
A: 

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>
Arthur Ronald F D Garcia