• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

populate the select when page is displayed first time

 
jacob deiter
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JSP page with combo box and wants to populate the combo box when page is displayed first time ?
How it can be done in JSP?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The same way that you create any other HTML markup. Populate the <select> with the <option> elements that represent the choices.
 
jacob deiter
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry by mistake It happened

in which method i have to write the code? ex:init method
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are no methods in a JSP.

Are you brand new to JSP? You write the "code" (remember, no Java code in a JSP anymore!) wherever it needs to appear in the HTML markup.
Your question makes me think that this might be your first JSP.

You're also not giving us much to go on. Are the options fixed? If so, just write the HTML for the option elements. Coming from a DB? A properties file? Elsewhere?
 
jacob deiter
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ Bear Bibeault

it is from DB
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so here's the flow:
  • The page controller asks the Model for the values. Note that this should be returned as a Java collection, not a result set. All DB artifacts stay in the Model.
  • A Map is especially well suited to options that have different value attributes than display text. Otherwise, a List is sufficient.
  • The controller places the List or Map into request scope as a scoped variable.
  • The controller forwards to the JSP to render the view.
  • In the JSP, the JSTL <c:forEach> tag is used to iterate over the List or Map and render the <option> elements.

  •  
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic