The specific answer depends, of course, on what we're talking about -- a JList, or JComboBox, or a LIST in a JSP, or an SWT List, or ... Once you specify what you're asking about, exactly, it's generally a simple question. In fact, most of the above options simply have an API method that returns an array or Collection of the selected items.
Originally posted by Ernest Friedman-Hill: The specific answer depends, of course, on what we're talking about -- a JList, or JComboBox, or a LIST in a JSP, or an SWT List, or ... Once you specify what you're asking about, exactly, it's generally a simple question. In fact, most of the above options simply have an API method that returns an array or Collection of the selected items.
You didn't answer my question -- you just restated your original post without giving any new information! [ October 04, 2004: Message edited by: Ernest Friedman-Hill ]
Sorry for not being very clear about my question. Okay, I have a clearer idea about what I am working on:
I get a Collection of JavaBeans from a database table. I then create a table in a Java Server Page (JSP). Each row of the table displays the properties of the individual JavaBean in the Collection. And each row has a check box. Putting a check mark in a check box results in submiting the email address of a mail recipient.
Users of the JSP make multiple selections using the check boxes. The multiple choices can result in tens of thousands of selections. The size of the selections is a variable.
The goal is to send a batch of e-mails out. I have to store the multiple choices somewhere. Originally, I thought it was an array. Now, an array is not a good idea because the size of the selections is unknown.
How do I convert multiple choices into some kind of storage and then a batch mail can be sent out?
Joined: Aug 29, 2003
Let me see if I could explain my self better.
I am creating check boxes in a JSP. I am showing the HTML code to make it simple:
I have to get all the "e-mail addresses" of those who are selected (if a client puts a check mark in the check box). Therefore, I cannot predict ahead of time how many e-mail addresses will be read by my web application.
In a servlet, how to get all the values of the "emailAddress" from a long list shown above (that is displayed by code in a JSP) and put them in a proper storage; for example, ArrayList, Vector, or ......
Yes, I am going to have String(s) - e-mail address(es).
My questions are:
1. Because I may have tens of thousands of String(s) and the actual numbers of those String(s) cannot be predicted, shoudl I use an "Array"? What is proper to use in my case; ArrayList or something else?
2. In a servlet, how to get the values of checked boxes in a JSP?
[EJFH: Fixed CODE tag.] [ October 05, 2004: Message edited by: Ernest Friedman-Hill ]
author and iconoclast
OK, now you've explained your question well enough to answer.
The code that handles the form submittal could be in the same JSP (although in a different invocation) or it could be in a servlet. I'm not going to talk about application architectures here: other people in this forum will be sure to chime in on that.
In either case, all the values of the checked emailAddress inputs will be available together as a String array by calling getParameterValues("emailAddress") on your HttpServletRequest object, so I think you don't need to worry about what you asked about. [ October 05, 2004: Message edited by: Ernest Friedman-Hill ]
Joined: Aug 29, 2003
Should I created a String ArrayList instead of a String Array by calling getParameterValues("emailAddress") on the HttpServletRequest object?
The length of this Array is a variable and could be a very large one.
Vector is not a good choice because "thread safe' is not required.
But when you make the call to getParameterValues() an array of the correct size, no matter how large, is returned already filled in with request parameter values. Why do you feel the need to change it?
subject: How To Make an Array from Multiple Selection of a Drop-Down Menu (or Scrollable List)