Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to poplulate a Spring form dropdown via SQL table

 
Vishal Hegde
Ranch Hand
Posts: 1077
Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

I wanted to know, how to poplulate a Spring form dropdown via SQL Table.

I tried googling it, but it was of no help.
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would call one of your methods in your @Respostiory. The method would return a collection of options to populate your drop down box with. It might look something like this if your drop down were categories.



The database look-up work would be done in myRepository.

Once you have the list your question merely becomes how to populate a selection box.

If you are just selecting a list of Strings it is very simple. If you are using objects there is a little more to it. See this thread from a couple days ago. Pieces of it may be relevant to you.

http://www.coderanch.com/t/591440/Spring/ID-isn-binded-form-object

Also have a look at the reference documentation:
http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/view.html#view-jsp-formtaglib-selecttag
 
Vishal Hegde
Ranch Hand
Posts: 1077
Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Bill,

I want it in JSTL tag format Like the below lines


 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like you are doing what the options tag does for you. If you want to do it that way you can but it should be within a select. You also need to use the Spring taglib for your select and option elements if you want it bound to your object.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic