Creating and then accessing lots of RADIO buttons

Hi,

I want to dynamically create lots of radio buttons on a jsp page.

I want to create some large numbers ofradio button pairs as below.

<INPUT type="checkbox" name="checks" value="check1">1

<INPUT type="checkbox" name="checks" value="check2">2

<INPUT type="checkbox" name="checks1" value="check3">1

<INPUT type="checkbox" name="checks1" value="check4">2

I can create unlimited radio buttons using the code below

<%

for(int count = 0; count < 100; count++)

{

out.print("<INPUT type=\"radio\" name=\"Radio" + count +"\" value=\"" + count +"\" />Positive");

out.print("<INPUT type=\"radio\" name=\"Radio" + count +"\" value=\"" + count +"\" />Negative");

count++;

out.print("<br>");

}

%>

But the problem is then how to access the values of these radio buttons when this page is posted to a Servlet?

Is there any way of creating large pair of radio buttons in JSP?

or someobject representing Array of radio buttons?

Thanks for reading.

Message was edited by:

vsood2

[1769 byte] By [vsood2a] at [2007-11-27 8:04:03]
# 1

Maybe I need to simplify the question more....

I use to create JRadioButton

private JRadioButton [] pButton = new JRadioButton[300];

Something like the above....

but I dono how to do the same thing in JSP/Servlet environment.

Please help!

vsood2a at 2007-7-12 19:46:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

To read the values in the servlet you can use getParameterValues() to get multiple values for an element of one name; like a series of checkboxes.

You could also use getParameterNames() to return an Enumeration of parameters that are available.

Since you're generating the radio buttons as pairs with a fixed format, you could just do this:

for ( i=0; i < upperlimit; i++ ) //figure out some way to find out upper limit for the loop; hidden field or something could contain the number

{

String[] currentSetOfRadioButtons = request.getParamterValues("Radios" + i ); //so you'll get Radios0, Radios1 etc

}

nogoodatcodinga at 2007-7-12 19:46:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...