aspose file tools*
The moose likes JSP and the fly likes populate the select when page is displayed first time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "populate the select when page is displayed first time " Watch "populate the select when page is displayed first time " New topic
Author

populate the select when page is displayed first time

jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 576
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

Joined: Jan 10, 2002
Posts: 60041
    
  65

The same way that you create any other HTML markup. Populate the <select> with the <option> elements that represent the choices.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 576
sorry by mistake It happened

in which method i have to write the code? ex:init method
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60041
    
  65

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

Joined: Apr 02, 2008
Posts: 576
@ Bear Bibeault

it is from DB
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60041
    
  65

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.

  •  
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: populate the select when page is displayed first time
     
    Similar Threads
    dynamically adding component to JPanel
    Swing + JComboBox
    How do I populate dynamic combox items
    How to insert at runtime using AJAX
    Combo Box