This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
    Bookmark Topic Watch Topic
  • New Topic

populating drop down list from database table

 
George Gates
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
hi
i have following questions:
1) How can we populate a drop down list from a database table? My drop down list should contain all the section numbers that satisfy a particular condition. I have written a query that would fetch all the correct section numbers. Now I want to add them into a drop down menu. Can someone tell me any way to achieve it?

2) Is there any way by which we can populate a drop down using all the elements in the array? For example:
Let the array be
String s []={"abc","def","xyz"};
How do i get the three string instances into the drop down menu?

3) Any other data structure (HashMap or Hashtable) will also do.

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
If the value and the display text for the select options will be the same, any list element will do to store the values. Do not, under any circumstances pass the resultset to UI code. Copy the values to a List or array and pass that after closing the resultset.

If the value and display text are to be different a sorted Map (TreeMap for example) can be useful to pass the value/text pairs.

Once the list is passed to the page controller, it can place the list as a scoped variable in request scope.

From there, the JSP can use JSTL and EL to easily create the <select> and its <option> elements from the list.
[ July 13, 2008: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please be sure to post in the proper forum. I am closing this in view of your JSF forum post.
 
I agree. Here's the link: http://aspose.com/file-tools
    Bookmark Topic Watch Topic
  • New Topic