• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

drop down values in jsp

 
Rajah Nagur
Ranch Hand
Posts: 239
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello all,
what is the best way to retreive the drop down data from the database to display in a jsp in a 3 tier env? what abt the dependent drop downs.?
 
Greg Charles
Sheriff
Posts: 2984
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You really can't do anything fundamentally different with JSP from what you can do with HTML. You still make your drop down box with HTML form elements, but instead of hard-coding the values, you can pull them from a database or something. You can use Java Script to populate dependant drop downs dynamically.
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're using an MVC style architecture then you could retrieve the contents of the lists from the database, and place it request scope ready to be rendered by the JSP view. This rendering could be implemented using a view helper such as a custom tag.
Check out Chapter 8 of my book (in PDF format) that has an example custom tag to help render drop downs. Say that you have a collection of JavaBeans in that collection representing countries, the tag takes the name of the bean properties that will be used for the key and display values (e.g. country ID and name), and uses Java's reflection mechanism to access them.
Hope it's useful...
Simon
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic