tags:

views:

21

answers:

1

Hi,

Does anybody have an idea on how to auto select option tag?

I checked at the spring form tag library but cant see any property related to an option value being selected by default when the JSP is rendered.

I basically have this

<p>
    <label for="plantLabel" class="label">Plant:</label> 
    <form:select path="strPlant" >
        <form:option value="-" label="" />
        <form:options items="${plants}" itemLabel="strPlant"
            itemValue="strPlant" />
    </form:select>
</p>

Thanks

+1  A: 

The "selected Option" will be calculate by Spring MVC based on the path="" attribute.

In above case I think,

Either the value of path="strPlant" is null

OR

the array/collection/map represented by items="${plants}" attribute does not contain an element corresponding to path="strPlant" value.

e.g. if path="strPlant" results in String NeemTree, items="" must have NeemTree as element.

itemLabel="strPlant" and itemValue="strPlant" make sense only if you are passing an instance of HashMap to items="" attribute.

16.2.4.11

becomputer06
@beComputer06 Thank you...I got it to work...
Mark Estrada