| Author |
what Collection to use?
|
Ilja Smoli
Ranch Hand
Joined: Dec 02, 2001
Posts: 64
|
|
Hi gurus.. Question is what Collection type is most used and easier to iterate in html ptions for instance? Cause my problem is: I have a DB table with 2 columns: branch_id and branch_name. Then I have a jsp file with form with select menu to choose branch from. Looks like (not workin): Action form bean has a get/set method for it: What i'd like to do is: display the list of branches with <html ptions> tag And to have in this list options with values from branch_id column, but display a branch_name column. Standart html would look like: Then i'd like 1 of these branches to be pre selected depends on user's branch_id (taken from session for eg.) I guess In my Action class (from where user get this jsp page with form), I have to put some collection in scope to iterate it on jsp. And additionaly i have to call setBranch_id method from actionForm with user's branch_id value to get it selected Any ideas? thx in advance
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26168
|
|
Ilja, You can use any collection type you want. For example, ArrayList is common. You are correct that you need the branch_id in your form. Somewhere else, you need to have two parallel collections. One is for the names and one is for the values in the select list. Suppose you have the collections, optionNames and optionValues in a bean called branches. You could then use: (edited because a messed up the code tags) [ March 22, 2004: Message edited by: Jeanne Boyarsky ]
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
Ilja Smoli
Ranch Hand
Joined: Dec 02, 2001
Posts: 64
|
|
Thx Jeanne.. I ve got the point Cheers
|
 |
 |
|
|
subject: what Collection to use?
|
|
|