permaculture playing cards*
The moose likes Spring and the fly likes How to poplulate a Spring form dropdown via SQL table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "How to poplulate a Spring form dropdown via SQL table" Watch "How to poplulate a Spring form dropdown via SQL table" New topic
Author

How to poplulate a Spring form dropdown via SQL table

Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

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.


http://www.lifesbizzare.blogspot.com || OCJP:81%
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1648
    
    7

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


[How To Ask Questions][Read before you PM me]
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

Dear Bill,

I want it in JSTL tag format Like the below lines


Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1648
    
    7

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to poplulate a Spring form dropdown via SQL table
 
Similar Threads
spring web flow-tiles
poplulate values of FormBean/reset/edit?
dynamically poplulate select menus based on first select menu
JSF Newbie: sending params to data provider from text field
populate a form with rows and save it back to DB?