Auto Select Option Tag by default in Spring MVC

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="--Select Please--" />
        <form:options items="${plants}" itemLabel="strPlant"
            itemValue="strPlant" />
    </form:select>
</p>

and, I want an option from the list (ie. items="${plants}" , say 'NeemTree') to be shown as already selected when the page loades.

Thanks

Answers


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.

Spring Reference Documentation


Need Your Help

Mocha Monitor Application Output

node.js mocha

I'm building a logging module for my web app in nodejs. I'd like to be able to test using mocha that my module outputs the correct messages to the terminal. I have been looking around but haven't f...

reading graph from titan using python without rexter server

python graph hbase titan

I am working on python and needs to read data(need to know available available vertices, relationships between them and properties of each vertex) in Titan Graph database(may be in to excel for some