Reputation: 163
I have an object with countryName attribute and method getCountryName() get all countryName from database by using below query:
SELECT DISTINCT countryName from jobs
Now i want to pass this list into a form at jsp page as below:
<form:form>
<form:select>
<form:options> List of country name </form:options>
</form:select>
</form:form>
Anyone have ideas? I'm using Spring 4.0.0 REALEASE.
For easier understanding, i already had an annotation in my controller
@ModelAttribute("countries")
public List<String> getListCountryName(){
return dao.getCountryName() ;
}
How can i pass that list to view in spring's form tag?
Upvotes: 0
Views: 1157
Reputation: 3274
Write some thing like this:
<form:form>
<form:select path="commandAttribute">
<form:option value="-" label="List of country namet"/>
<form:options items="${countryList}" itemValue="countryName " itemLabel="countryName "/>
</form:select>
</form:form>
Reference http://www.mkyong.com/spring-mvc/spring-mvc-dropdown-box-example/
Upvotes: 1