• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Populating a select list with values from database

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
</select>
</spring:bind>
=============================

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
 
Sheriff
Posts: 67266
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to ask Spring questions in the Frameworks forum. I have moved this post there for you.
 
yusuf nazir
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

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


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

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();
session.beginTransaction();
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");
session.getTransaction().commit();
return opdrachtGeversList;
} catch (RuntimeException re) {
throw re;
}
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!