GeeCON Prague 2014*
The moose likes JSP and the fly likes how to add the values to combo box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "how to add the values to combo box" Watch "how to add the values to combo box" New topic
Author

how to add the values to combo box

sravan ku
Greenhorn

Joined: Feb 15, 2013
Posts: 7
Hi Everyone,

This is my code snippet


sample output : directory 1 ,dir 2,dir3


My query :

Can any one please tell me how to add this output to combo box in jsp page ?


thanks,
ksk

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61305
    
  66

OK, there's a lot to talk about here:

Frist of all, please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information. Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.

I've gone ahead and added the code tags for you. See how much easier the code is to read?

Secondly, you should not be using Java code in a JSP. That's a bad practice from 12 years ago! Do you not feel it is time to modernize? Please see this JspFaq entry.

Another point, correct terminology is important so that we all understand what's being talke about: HTM has no "combo box". Please see
HtmlHasNoComboBox.

What would be best is if you obtained the list for files to be displayed as options in the dropdown in the page controller and passed it to the JSP as a scoped variable. The in the JSP, you could use the JSTL and EL to iterate over the list and create option elements.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61305
    
  66

For example, if you were to put a List of the file names into request scope with the name fileList, you could use code similar to the following:

sravan ku
Greenhorn

Joined: Feb 15, 2013
Posts: 7
Thanks for the reply .

Pardon me ,I am new to this forum I didn't read the guidelines :-( any how thanks for the first step.

I want to display each directory in jsp combo box .

Like > If I am having 3 directories like x,y,z . I want all these directories in the combo box .



PREVIOUSLY I was done like this but all the directories are appearing in a single line .
I want each one of that directory in different line .

Thanks,
ksk
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61305
    
  66

sravan ku wrote:I want to display each directory in jsp combo box .

Again, there is no such thing as a "combo box". Most people use the term dropdown or select element.

Like > If I am having 3 directories like x,y,z . I want all these directories in the combo box .

I already showed you how to do it using JSTL and EL.
sravan ku
Greenhorn

Joined: Feb 15, 2013
Posts: 7
@Bear Bibeault

Okay got it .

I will try and get back to you soon ..

I will keep in mind to use the correct terminology .



Thanks,
ksk
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61305
    
  66

Almalyn caguioa
Greenhorn

Joined: Feb 01, 2013
Posts: 8
you can use the following code

ArrayList s = new ArrayList();

s.Add("aaa"); s.Add("bbb"); s.Add("ccc"); ...

this.comboBox2.DataSource = s;

(or)

string[] s = {"a","b","c","d","1","2","3","4"};

this.comboBox2.DataSource = s;

(or)

char[] s = {'a','b','c'};

this.comboBox2.DataSource = s;

(or)

this.comboBox2.Items.Add("Select");
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61305
    
  66

Ummm, none of that code seems at all relevant to the issue.
 
GeeCON Prague 2014
 
subject: how to add the values to combo box