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

dynamic drop down boxes

 
liliya woland
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,
I have a rather long list of select options, and I also have a mysql table that contains that very same data. I'd like to be able to streamline the data from the table into my select menu.
I know enough of .jsp (and some java) to read data from a table but don't know enough to do something like this. I know that I need to write a bean, but that's about all. Could anyone please refer me to any code examples so I could see what needs to happen? Thanks in advance.
 
vjy chin
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
One simple way is to connect to the database and get the values and store them in an array or arraylist.
The inside the select box, you just need to iterate the array or arraylist.



Hope this helps
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64830
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Though preferably with the JSTL rather than scriptlets.
 
liliya woland
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again,
I did try the code above and for some reason my options get populated with "vOptions.get(i)" instead of data.
I understand the problem has to do with my syntax, but could someone tell me please what syntax to use to get the array data out?
....
Vector vOptions = new Vector();
while(rs.next()){

vOptions.addElement(rs.getString(1));
}
.... then:

<select name="T50">
<%
for (int i = 0; i< vOptions.size(); i++) {
%>
<option value="<%=vOptions.get(i)%>">vOptions.get(i)</option>
<%
}
%>
</select>
 
liliya woland
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it! ... Just had to do <%=vOptions.get(i)%>
 
vjy chin
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OOPS, Sorry I forgot the <%= %> .
Good you noticed it and got the results.

Thanks
 
mamidi subrahmanyam
Greenhorn
Posts: 19
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi liliya

Better use ArrayList than Vector.

(if there is no problem with performance issues, then you can continue with Vector also)
[ April 13, 2006: Message edited by: mamidi subrahmanyam ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic