File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Application Frameworks and the fly likes Populating a select list with values from database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Populating a select list with values from database" Watch "Populating a select list with values from database" New topic

Populating a select list with values from database

yusuf nazir

Joined: May 13, 2009
Posts: 12
Hi all,

I'm building an application using spring mvc for the front end. I would appreciate any help as to how I can populate a select list with values.
what i have now:
<spring:bind path="klantId">
<select name="klantId">
<option value="1">test-txt-bestand</option>
<option value="2">nog te specificeren</option>

the list that i'm currently trying to generate will contain about 20 values.
How can i populate it? I'm using a mysql database for the backend.

thanks in advance
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63858

Please be sure to ask Spring questions in the Frameworks forum. I have moved this post there for you.

[Asking smart questions] [About Bear] [Books by Bear]
yusuf nazir

Joined: May 13, 2009
Posts: 12
Hi all,

I found the solution. In case anyone needs is it you can read through it.

in jsp:
<spring:bind path="klantId">
<form:select path="klantId" items="${opdrachtGeversList}" itemValue="opdrachtGeverId" itemLabel="opdrachtGeverNaam"/>

i don't think the spring bind is needed.

Java classes

public class OpdrachtGevers {

private String opdrachtGeverNaam;
private Integer opdrachtGeverId;
private String profile;

public String getOpdrachtGeverNaam() {
return opdrachtGeverNaam;
public void setOpdrachtGeverNaam(String opdrachtGeverNaam) {
this.opdrachtGeverNaam = opdrachtGeverNaam;
public Integer getOpdrachtGeverId() {
return opdrachtGeverId;
public void setOpdrachtGeverId(Integer opdrachtGeverId) {
this.opdrachtGeverId = opdrachtGeverId;
public String getProfile() {
return profile;
public void setProfile(String profile) {
this.profile = profile;

Java DAO class
public List<OpdrachtGevers> retrieve() {
try {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
String sqlQuery = " from OpdrachtGevers as opdrachtGevers where lower(opdrachtGevers.profile) not like "+"'general'"+" ORDER BY opdrachtGevers.opdrachtGeverNaam";
System.out.println("query executing");
List<OpdrachtGevers> opdrachtGeversList = (List<OpdrachtGevers>) session.createQuery(sqlQuery).list();
System.out.println("query executed");
return opdrachtGeversList;
} catch (RuntimeException re) {
throw re;
I agree. Here's the link:
subject: Populating a select list with values from database
It's not a secret anymore!