aspose file tools*
The moose likes JSP and the fly likes Using a List for Field Population Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Using a List for Field Population" Watch "Using a List for Field Population" New topic
Author

Using a List for Field Population

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1446
    
    1
I have a remote table with users names. I have a JSP that has several fields for the user to fill in. Two of them are first and last name(the one logged on to the web app is not always the one whose name will go on the form). Can and if how would I set this up so the user could select the name from a list.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61226
    
  66

Use a <select> rather than a text field.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1446
    
    1
Can you give me some idea of how to populate the drop down box dynamically with the result set of my remote connection?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61226
    
  66

By "remote connection" I assume you mean a database?

Assuming that your web app is patterned using best-practice MVC patterns, it pretty straight-forward:
  • The page controller for the JSP will call a model class that retrieves the list from the DB.
  • If the list is not already in a suitable format, such as a List implementation, it should re-format the data as such
  • The page controller places the list in request scope as a scoped variable with a suitable name
  • On the JSP, the JSTL and EL are used to iterate over the list and create the options for the select element


  • If the options are to have values that are different from the displayed text, the list can be sets of name/value pairs.
    [ May 16, 2007: Message edited by: Bear Bibeault ]
    Steve Dyke
    Ranch Hand

    Joined: Nov 16, 2004
    Posts: 1446
        
        1
    Is it going to be possible to have one list with first name and last name and have that fill in two separate fields on the form?
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61226
        
      66

    Two lists.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Using a List for Field Population