You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Caroline Jen <ji...@yahoo.com> on 2004/10/05 22:53:14 UTC

Array? ArrayList? or .....?

I am creating check boxes in a JSP. I am showing the
HTML code to make it simple to illustrate my question.

code: 
________________________________________

<H2>Check As Many As You Wish</H2>
 <INPUT TYPE="checkbox" NAME="emailAddress"
VALUE="john_doe@earthlink.net">John Doe</INPUT>
 <INPUT TYPE="checkbox" NAME="emailAddress"
VALUE="jane_doe@yahoo.com">Jane Doe</INPUT>
 // followed by tens of thousands of <INPUT
TYPE="checkbox" NAME="emailAddress" .......> tags 
________________________________________


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 (servlet) after the form is submitted.

Yes, I am going to have String(s) - e-mail
address(es).

String [] emailBoxes =
request.getParameterValues("emailAddress"); 

My questions is:

Because I may have tens of thousands of String(s) and
the actual numbers of those String(s) cannot be
predicted (we do not know how many will be selected by
a certain client), should I still use an "Array"? What
is proper to use in my case; ArrayList or something
else?  Is this Java statement still a proper one?

String [] emailBoxes =
getParameterValues("emailAddress");



		
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Array? ArrayList? or .....?

Posted by Jeff Beal <jb...@webmedx.com>.
http://struts.apache.org/faqs/newbie.html#multiple talks briefly about 
doing this.  It doesn't discuss the issue of arrays vs. ArrayList, but 
the example is using arrays, so I assume that's the recommended approach.

Also, and just an FYI, the HTML you've included is invalid.  INPUT 
elements are not allowed to have text inside of them.  Instead, put your 
INPUT element inside a LABEL:
<LABEL><INPUT TYPE="checkbox" NAME="emailAddress" 
VALUE="john_doe@earthlink.net" />John Doe</LABEL>

See http://www.w3.org/TR/html401/interact/forms.html#edef-LABEL for more 
information on using the LABEL element.

-- Jeff

Caroline Jen wrote:
> I am creating check boxes in a JSP. I am showing the
> HTML code to make it simple to illustrate my question.
> 
> code: 
> ________________________________________
> 
> <H2>Check As Many As You Wish</H2>
>  <INPUT TYPE="checkbox" NAME="emailAddress"
> VALUE="john_doe@earthlink.net">John Doe</INPUT>
>  <INPUT TYPE="checkbox" NAME="emailAddress"
> VALUE="jane_doe@yahoo.com">Jane Doe</INPUT>
>  // followed by tens of thousands of <INPUT
> TYPE="checkbox" NAME="emailAddress" .......> tags 
> ________________________________________
> 
> 
> 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 (servlet) after the form is submitted.
> 
> Yes, I am going to have String(s) - e-mail
> address(es).
> 
> String [] emailBoxes =
> request.getParameterValues("emailAddress"); 
> 
> My questions is:
> 
> Because I may have tens of thousands of String(s) and
> the actual numbers of those String(s) cannot be
> predicted (we do not know how many will be selected by
> a certain client), should I still use an "Array"? What
> is proper to use in my case; ArrayList or something
> else?  Is this Java statement still a proper one?
> 
> String [] emailBoxes =
> getParameterValues("emailAddress");
> 
> 
> 
> 		
> _______________________________
> Do you Yahoo!?
> Declare Yourself - Register online to vote today!
> http://vote.yahoo.com



Re: Array? ArrayList? or .....?

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Caroline Jen" <ji...@yahoo.com>
> 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 (servlet) after the form is submitted.

I'm confused... is this a Struts webapp? Why use getParameterValues() when
the framework will populate your ActionForm for you?

In this situation I have a List or Map of items (usually DTOs) to be
selected from, use <c:forEach> to display them, and have a String[] in the
ActionForm which Struts will populate with the user's choices.

And... tens of thousands of choices?!  That's a user-interface nightmare.
There has to be a way to narrow down the selection before you present them
with checkboxes, nobody is going to go through a list that large.

-- 
Wendy Smoak


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org