- From: Nirmalkumar - Patil <npatil@cs.tamu.edu>
- Date: Mon, 21 Jul 1997 13:28:31 -0500 (CDT)
- To: www-jigsaw@w3.org
Hello all ,
I am in the process of learning more abt Jigsaw. I tried to have
a multiple selection box in a form as follows :
<select multiple name="favcolor" size = 3>
<option>green
<option>aquamarine
<option>emerald
<option>turquoise
<option>aqua
<option>black
<option>yellow
</select>
I used data.getMultipleValues("favcolor") to obtain the array of selected
options .. but I get a "Document contains no data" from the browser
when I try to run this. I have attached the code below.
An httpexception is thrown when I try to access an element
of the array that is not been allocated memory.
I was able to work around this by catching the ArrayOutOfBoundsException and
setting a flag in the catch loop .. but there must be a better way to do this. .. Or rather how do I extract values from a String array whose index I don't
know ?
Would appreciate any help here.
Thanks,
Nirmal
-----------------------------
package w3c.jigsaw.contrib;
import java.util.*;
import w3c.jigsaw.http.*;
import w3c.jigsaw.forms.*;
import w3c.jigsaw.html.*;
import w3c.tools.store.*;
import w3c.www.http.*;
import w3c.jigsaw.resources.*;
public class MyFormResource extends PostableResource {
String dummy = new String();
public Reply handle(Request request, URLDecoder data)
throws HTTPException {
String tmp[] = new String[20];
HtmlGenerator g = new HtmlGenerator("myform"); // set title
g.append("<h1>data obtained</h1>");
g.append("<ul>");
tmp = data.getMultipleValues("favcolor");
int i=0;
while ( tmp[i] != null ) {
System.out.println(" AFTER "+i+" :" + tmp[i]);
g.append("<li>Testing select : ", tmp[i]);
i++;
if( tmp[i] == (String)null )
break;
}
System.out.println("\ni is : "+i);
g.append("</ul>");
Reply reply = request.makeReply(HTTP.OK);
reply.setStream(g);
return reply;
}
public MyFormResource() {
}
}
Received on Monday, 21 July 1997 14:30:45 UTC